Example #1
0
 /**
  * Test sending cookie header with raw value
  *
  * @group fix-double-encoding-problem-about-cookie-value
  */
 public function testRawCookiesInRequestHeaders()
 {
     $this->_client->setConfig(array('encodecookies' => false));
     $this->_client->addCookie('foo', 'bar=baz');
     $this->_client->send();
     $cookieValue = 'Cookie: foo=bar=baz';
     $this->assertContains($cookieValue, $this->_client->getLastRawRequest(), 'Request is expected to contain the entire cookie "keyname=raw_value"');
 }
 /**
  * @group 2774
  * @group 2745
  */
 public function testUsesProvidedArgSeparator()
 {
     $this->client->setArgSeparator(';');
     $request = new Request();
     $request->setUri('http://framework.zend.com');
     $request->setQuery(array('foo' => 'bar', 'baz' => 'bat'));
     $this->client->send($request);
     $rawRequest = $this->client->getLastRawRequest();
     $this->assertContains('?foo=bar;baz=bat', $rawRequest);
 }
 /**
  * @param Client $target
  * @return $this
  */
 public function profilerFinish(Client $target)
 {
     $current =& $this->profiles[$this->currentIndex];
     $current['end'] = microtime(true);
     $current['elapse'] = $current['end'] - $current['start'];
     $current['request'] = (string) $target->getLastRawRequest();
     $current['response'] = (string) $target->getLastRawResponse();
     $this->currentIndex++;
     return $this;
 }
Example #4
0
 /**
  * @group ZF2-78
  * @dataProvider parameterArrayProvider
  */
 public function testContentTypeAdditionlInfo($params)
 {
     $content_type = 'application/x-www-form-urlencoded; charset=UTF-8';
     $this->client->setUri($this->baseuri . 'testPostData.php');
     $this->client->setHeaders(array('Content-Type' => $content_type));
     $this->client->setMethod(\Zend\Http\Request::METHOD_POST);
     $this->client->setParameterPost($params);
     $this->client->send();
     $request = Request::fromString($this->client->getLastRawRequest());
     $this->assertEquals($content_type, $request->getHeaders()->get('Content-Type')->getFieldValue());
 }
Example #5
0
 /**
  * Test sending cookie header with raw value
  *
  * @group fix-double-encoding-problem-about-cookie-value
  */
 public function testRawCookiesInRequestHeaders()
 {
     if (!constant('TESTS_ZEND_HTTP_CLIENT_ONLINE')) {
         $this->markTestSkipped('Zend\\Http\\Client online tests are not enabled');
     }
     $this->_client->setOptions(array('encodecookies' => false));
     $this->_client->addCookie('foo', 'bar=baz');
     $this->_client->send();
     $cookieValue = 'Cookie: foo=bar=baz';
     $this->assertContains($cookieValue, $this->_client->getLastRawRequest(), 'Request is expected to contain the entire cookie "keyname=raw_value"');
 }
Example #6
0
 /**
  * Test that we properly calculate the content-length of multibyte-encoded
  * request body
  *
  * This may file in case that mbstring overloads the substr and strlen
  * functions, and the mbstring internal encoding is a multibyte encoding.
  *
  * @link http://framework.zend.com/issues/browse/ZF-2098
  */
 public function testMultibyteRawPostDataZF2098()
 {
     $this->_client->setAdapter('Zend\\Http\\Client\\Adapter\\Test');
     $this->_client->setUri('http://example.com');
     $bodyFile = __DIR__ . '/_files/ZF2098-multibytepostdata.txt';
     $this->_client->setRawBody(file_get_contents($bodyFile));
     $this->_client->setEncType('text/plain');
     $this->_client->setMethod('POST');
     $this->_client->send();
     $request = $this->_client->getLastRawRequest();
     if (!preg_match('/^content-length:\\s+(\\d+)/mi', $request, $match)) {
         $this->fail("Unable to find content-length header in request");
     }
     $this->assertEquals(filesize($bodyFile), (int) $match[1]);
 }
Example #7
0
    public function testClientUsesAcceptEncodingHeaderFromRequestObject()
    {
        $client = new Client();

        $client->setAdapter('Zend\Http\Client\Adapter\Test');

        $request = $client->getRequest();

        $acceptEncodingHeader = new AcceptEncoding();
        $acceptEncodingHeader->addEncoding('foo', 1);
        $request->getHeaders()->addHeader($acceptEncodingHeader);

        $client->send();

        $rawRequest = $client->getLastRawRequest();

        $this->assertNotContains('Accept-Encoding: gzip, deflate', $rawRequest, null, true);
        $this->assertNotContains('Accept-Encoding: identity', $rawRequest, null, true);

        $this->assertContains('Accept-Encoding: foo', $rawRequest);
    }
Example #8
0
 public function testIfClientDoesNotForwardAuthenticationToForeignHost()
 {
     // set up user credentials
     $user = '******';
     $password = '******';
     $encoded = Client::encodeAuthHeader($user, $password, Client::AUTH_BASIC);
     $testAdapter = new Test();
     $client = new Client(null, array('adapter' => $testAdapter));
     // set up two responses that simulate a redirection from example.org to example.com
     $testAdapter->setResponse("HTTP/1.1 303 See Other\r\n" . "Location: http://example.com/part2\r\n\r\n" . "The URL of this page has changed.");
     $testAdapter->addResponse("HTTP/1.1 200 OK\r\n\r\n" . "Welcome to this Website.");
     // set auth and do request
     $client->setUri('http://example.org/part1')->setAuth($user, $password, Client::AUTH_BASIC);
     $response = $client->setMethod('GET')->send();
     // the last request should NOT contain the Authorization header,
     // because example.com is different from example.org
     $this->assertTrue(strpos($client->getLastRawRequest(), $encoded) === false);
     // set up two responses that simulate a rediration from example.org to sub.example.org
     $testAdapter->setResponse("HTTP/1.1 303 See Other\r\n" . "Location: http://sub.example.org/part2\r\n\r\n" . "The URL of this page has changed.");
     $testAdapter->addResponse("HTTP/1.1 200 OK\r\n\r\n" . "Welcome to this Website.");
     // set auth and do request
     $client->setUri('http://example.org/part1')->setAuth($user, $password, Client::AUTH_BASIC);
     $response = $client->setMethod('GET')->send();
     // the last request should contain the Authorization header,
     // because sub.example.org is a subdomain unter example.org
     $this->assertFalse(strpos($client->getLastRawRequest(), $encoded) === false);
     // set up two responses that simulate a rediration from sub.example.org to example.org
     $testAdapter->setResponse("HTTP/1.1 303 See Other\r\n" . "Location: http://example.org/part2\r\n\r\n" . "The URL of this page has changed.");
     $testAdapter->addResponse("HTTP/1.1 200 OK\r\n\r\n" . "Welcome to this Website.");
     // set auth and do request
     $client->setUri('http://sub.example.org/part1')->setAuth($user, $password, Client::AUTH_BASIC);
     $response = $client->setMethod('GET')->send();
     // the last request should NOT contain the Authorization header,
     // because example.org is not a subdomain unter sub.example.org
     $this->assertTrue(strpos($client->getLastRawRequest(), $encoded) === false);
 }