Beispiel #1
0
 public function testReusesHandles()
 {
     Server::flush();
     $response = ['status' => 200];
     Server::enqueue([$response, $response]);
     $a = new CurlHandler();
     $request = ['http_method' => 'GET', 'headers' => ['host' => [Server::$host]]];
     $a($request);
     $a($request);
 }
 public function testExtractsErrors()
 {
     $request = ['http_method' => 'GET', 'headers' => ['host' => ['127.0.0.1:123']], 'future' => true];
     Server::flush();
     Server::enqueue([['status' => 202]]);
     $a = new CurlMultiHandler();
     $response = $a($request);
     $this->assertInstanceOf('GuzzleHttp\\Ring\\Future\\FutureArray', $response);
     $this->assertEquals(CURLE_COULDNT_CONNECT, $response['curl']['errno']);
     $this->assertNotEmpty($response['curl']['error']);
 }
 public function testSupports100Continue()
 {
     Server::flush();
     Server::enqueue([['status' => '200', 'reason' => 'OK', 'headers' => ['Test' => ['Hello'], 'Content-Length' => ['4']], 'body' => 'test']]);
     $request = ['http_method' => 'PUT', 'headers' => ['Host' => [Server::$host], 'Expect' => ['100-Continue']], 'body' => 'test'];
     $handler = new StreamHandler();
     $response = $handler($request);
     $this->assertEquals(200, $response['status']);
     $this->assertEquals('OK', $response['reason']);
     $this->assertEquals(['Hello'], $response['headers']['Test']);
     $this->assertEquals(['4'], $response['headers']['Content-Length']);
     $this->assertEquals('test', Core::body($response));
 }
Beispiel #4
0
<?php

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/Client/Server.php';
use GuzzleHttp\Tests\Ring\Client\Server;
Server::start();
register_shutdown_function(function () {
    Server::stop();
});
 public function testSendsNonLazyFutures()
 {
     $request = ['http_method' => 'GET', 'headers' => ['host' => [Server::$host]], 'future' => true];
     Server::flush();
     Server::enqueue([['status' => 202]]);
     $a = new CurlMultiHandler();
     $response = $a($request);
     $this->assertInstanceOf('GuzzleHttp\\Ring\\Future\\FutureArray', $response);
     $this->assertEquals(202, $response['status']);
 }
Beispiel #6
0
 public static function start()
 {
     TestServer::start();
 }
Beispiel #7
0
 public function testParsesLastResponseOnly()
 {
     $response1 = ['status' => 301, 'headers' => ['Content-Length' => ['0'], 'Location' => ['/foo']]];
     $response2 = ['status' => 200, 'headers' => ['Content-Length' => ['0'], 'Foo' => ['bar']]];
     Server::flush();
     Server::enqueue([$response1, $response2]);
     $a = new CurlMultiHandler();
     $response = $a(['http_method' => 'GET', 'headers' => ['Host' => [Server::$host]], 'client' => ['curl' => [CURLOPT_FOLLOWLOCATION => true]]])->wait();
     $this->assertEquals(1, $response['transfer_stats']['redirect_count']);
     $this->assertEquals('http://127.0.0.1:8125/foo', $response['effective_url']);
     $this->assertEquals(['bar'], $response['headers']['Foo']);
     $this->assertEquals(200, $response['status']);
     $this->assertFalse(Core::hasHeader($response, 'Location'));
 }
Beispiel #8
0
 public function testMaintainsMultiHeaderOrder()
 {
     Server::flush();
     Server::enqueue([['status' => 200, 'headers' => ['Content-Length' => ['0'], 'Foo' => ['a', 'b'], 'foo' => ['c', 'd']]]]);
     $a = new CurlMultiHandler();
     $response = $a(['http_method' => 'GET', 'headers' => ['Host' => [Server::$host]]])->wait();
     $this->assertEquals(['a', 'b', 'c', 'd'], Core::headerLines($response, 'Foo'));
 }