Skip to content

Commit

Permalink
Merge pull request #49 from reactphp/set-http-version
Browse files Browse the repository at this point in the history
Set protocol version on request creation
  • Loading branch information
cboden committed Sep 24, 2015
2 parents 59bef8b + b500da5 commit cf8ca08
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function __construct(ConnectorInterface $connector, ConnectorInterface $s
$this->secureConnector = $secureConnector;
}

public function request($method, $url, array $headers = [])
public function request($method, $url, array $headers = [], $protocolVersion = '1.0')
{
$requestData = new RequestData($method, $url, $headers);
$requestData = new RequestData($method, $url, $headers, $protocolVersion);
$connector = $this->getConnectorForScheme($requestData->getScheme());

return new Request($connector, $requestData);
Expand Down
6 changes: 3 additions & 3 deletions src/RequestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class RequestData
private $method;
private $url;
private $headers;
private $protocolVersion;

private $protocolVersion = '1.0';

public function __construct($method, $url, array $headers = [])
public function __construct($method, $url, array $headers = [], $protocolVersion = '1.0')
{
$this->method = $method;
$this->url = $url;
$this->headers = $headers;
$this->protocolVersion = $protocolVersion;
}

private function mergeDefaultheaders(array $headers)
Expand Down
14 changes: 14 additions & 0 deletions tests/RequestDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ public function toStringReturnsHTTPRequestMessageWithProtocolVersion()
$this->assertSame($expected, $requestData->__toString());
}

/** @test */
public function toStringReturnsHTTPRequestMessageWithProtocolVersionThroughConstructor()
{
$requestData = new RequestData('GET', 'http://www.example.com', [], '1.1');

$expected = "GET / HTTP/1.1\r\n" .
"Host: www.example.com\r\n" .
"User-Agent: React/alpha\r\n" .
"Connection: close\r\n" .
"\r\n";

$this->assertSame($expected, $requestData->__toString());
}

/** @test */
public function toStringUsesUserPassFromURL()
{
Expand Down

0 comments on commit cf8ca08

Please sign in to comment.