Skip to content

Commit

Permalink
Test explicit HTTP/1.1 protocol version
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Feb 9, 2018
1 parent f1708c4 commit a8b61d3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ method:

```php
$request = new Request('OPTIONS', $url);
$request = $request->withProtocolVersion(1.1);
$request = $request->withProtocolVersion('1.1');

$browser->send($request)->then(…);
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"clue/block-react": "^1.0",
"clue/socks-react": "^0.8",
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35",
"react/http": "^0.7.2"
"react/http": "^0.8"
}
}
47 changes: 45 additions & 2 deletions tests/FunctionalBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Factory;
use React\Http\Response;
use React\Http\StreamingServer;
use React\Promise\Stream;
use React\Socket\Connector;
use React\Stream\ThroughStream;
use RingCentral\Psr7\Request;

class FunctionalBrowserTest extends TestCase
{
Expand Down Expand Up @@ -172,13 +174,12 @@ public function testPostString()
$this->assertEquals('hello world', $data['data']);
}

/** @group online */
public function testPostStreamChunked()
{
// httpbin used to support `Transfer-Encoding: chunked` for requests,
// but not rejects those, so let's start our own server instance
$that = $this;
$server = new \React\Http\Server(function (ServerRequestInterface $request) use ($that) {
$server = new StreamingServer(function (ServerRequestInterface $request) use ($that) {
$that->assertFalse($request->hasHeader('Content-Length'));
$that->assertNull($request->getBody()->getSize());

Expand Down Expand Up @@ -240,4 +241,46 @@ public function testPostStreamClosed()

$this->assertEquals('', $data['data']);
}

public function testSendsHttp10ByDefault()
{
$server = new StreamingServer(function (ServerRequestInterface $request) {
return new Response(
200,
array(),
$request->getProtocolVersion()
);
});
$socket = new \React\Socket\Server(0, $this->loop);
$server->listen($socket);

$this->base = str_replace('tcp:', 'http:', $socket->getAddress()) . '/';

$response = Block\await($this->browser->get($this->base), $this->loop);
$this->assertEquals('1.0', (string)$response->getBody());

$socket->close();
}

public function testSendsExplicitHttp11Request()
{
$server = new StreamingServer(function (ServerRequestInterface $request) {
return new Response(
200,
array(),
$request->getProtocolVersion()
);
});
$socket = new \React\Socket\Server(0, $this->loop);
$server->listen($socket);

$this->base = str_replace('tcp:', 'http:', $socket->getAddress()) . '/';

$request = new Request('GET', $this->base, array(), '', '1.1');

$response = Block\await($this->browser->send($request), $this->loop);
$this->assertEquals('1.1', (string)$response->getBody());

$socket->close();
}
}

0 comments on commit a8b61d3

Please sign in to comment.