public function testRequestParameters() { $url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my'; $url2 = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there'; $request = new Google_Http_Request($url); $request->setExpectedClass("Google_Client"); $this->assertEquals(2, count($request->getQueryParams())); $request->setQueryParam("hi", "there"); $this->assertEquals($url2, $request->getUrl()); $this->assertEquals("Google_Client", $request->getExpectedClass()); $urlPath = "/foo/bar"; $request = new Google_Http_Request($urlPath); $this->assertEquals($urlPath, $request->getUrl()); $request->setBaseComponent("http://example.com"); $this->assertEquals("http://example.com" . $urlPath, $request->getUrl()); $url3a = 'http://localhost:8080/foo/bar'; $url3b = 'foo=a&foo=b&wowee=oh+my'; $url3c = 'foo=a&foo=b&wowee=oh+my&hi=there'; $request = new Google_Http_Request($url3a . "?" . $url3b, "POST"); $request->setQueryParam("hi", "there"); $request->maybeMoveParametersToBody(); $this->assertEquals($url3a, $request->getUrl()); $this->assertEquals($url3c, $request->getPostBody()); $url4 = 'http://localhost:8080/upload/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there'; $request = new Google_Http_Request($url); $this->assertEquals(2, count($request->getQueryParams())); $request->setQueryParam("hi", "there"); $base = $request->getBaseComponent(); $request->setBaseComponent($base . '/upload'); $this->assertEquals($url4, $request->getUrl()); }
public function testRequestParameters() { $url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my'; $url2 = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there'; $request = new Google_Http_Request($this->getClient(), $url); $request->setExpectedClass("Google_Client"); $this->assertEquals(2, count($request->getQueryParams())); $request->setQueryParam("hi", "there"); $this->assertEquals($url2, $request->getUrl()); $this->assertEquals("Google_Client", $request->getExpectedClass()); $url3a = 'http://localhost:8080/foo/bar'; $url3b = 'foo=a&foo=b&wowee=oh+my'; $url3c = 'foo=a&foo=b&wowee=oh+my&hi=there'; $request = new Google_Http_Request($this->getClient(), $url3a . "?" . $url3b, "POST"); $request->setQueryParam("hi", "there"); $request->maybeMoveParametersToBody(); $this->assertEquals($url3a, $request->getUrl()); $this->assertEquals($url3c, $request->getPostBody()); }
public function parseResponse(Google_Http_Request $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 = $this->client->getIo()->getHttpResponseHeaders($metaHeaders); $status = substr($part, 0, strpos($part, "\n")); $status = explode(" ", $status); $status = $status[1]; list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false); $response = new Google_Http_Request(""); $response->setResponseHttpCode($status); $response->setResponseHeaders($partHeaders); $response->setResponseBody($partBody); // Need content id. $key = $metaHeaders['content-id']; if (isset($this->expected_classes[$key]) && strlen($this->expected_classes[$key]) > 0) { $class = $this->expected_classes[$key]; $response->setExpectedClass($class); } try { $response = Google_Http_REST::decodeHttpResponse($response); $responses[$key] = $response; } catch (Google_Service_Exception $e) { // Store the exception as the response, so succesful responses // can be processed. $responses[$key] = $e; } } } return $responses; } return null; }