public function parseResponse(Google_HttpRequest $response) { $contentType = $response->getResponseHeader('content-type'); $contentType = explode(';', $contentType); $boundary = false; foreach ($contentType as $part) { $part = explode('=', $part, 2); if (isset($part[0]) && 'boundary' == trim($part[0])) { $boundary = $part[1]; } } $body = $response->getResponseBody(); if ($body) { $body = str_replace("--{$boundary}--", "--{$boundary}", $body); $parts = explode("--{$boundary}", $body); $responses = array(); foreach ($parts as $part) { $part = trim($part); if (!empty($part)) { list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2); $metaHeaders = Google_CurlIO::parseResponseHeaders($metaHeaders); $status = substr($part, 0, strpos($part, "\n")); $status = explode(" ", $status); $status = $status[1]; list($partHeaders, $partBody) = Google_CurlIO::parseHttpResponse($part, false); $response = new Google_HttpRequest(""); $response->setResponseHttpCode($status); $response->setResponseHeaders($partHeaders); $response->setResponseBody($partBody); $response = Google_REST::decodeHttpResponse($response); // Need content id. $responses[$metaHeaders['content-id']] = $response; } } return $responses; } return null; }
/** * Set curl options. * * We overwrite this method to ensure that the data passed meets * the requirement of our curl implementation and so that the keys * are strings, and not curl constants. * * @param array $optCurlParams Multiple options used by a cURL session. * @return void */ public function setOptions($optCurlParams) { $safeParams = array(); foreach ($optCurlParams as $name => $value) { if (!is_string($name)) { $name = $this->get_option_name_from_constant($name); } $safeParams[$name] = $value; } parent::setOptions($safeParams); }
public function testAuthCache() { $io = new Google_CurlIO(); $url = "http://www.googleapis.com/protected/resource"; // Create a cacheable request/response, but it should not be cached. $cacheReq = new Google_HttpRequest($url, "GET"); $cacheReq->setRequestHeaders(array("Accept" => "*/*", "Authorization" => "Bearer Foo")); $cacheReq->setResponseBody("{\"a\": \"foo\"}"); $cacheReq->setResponseHttpCode(200); $cacheReq->setResponseHeaders(array("Cache-Control" => "private", "ETag" => "\"this-is-an-etag\"", "Expires" => "Sun, 22 Jan 2022 09:00:56 GMT", "Date: Sun, 1 Jan 2012 09:00:56 GMT", "Content-Type" => "application/json; charset=UTF-8")); $result = $io->setCachedRequest($cacheReq); $this->assertFalse($result); }