Skip to content

Commit cf8ca08

Browse files
committed
Merge pull request #49 from reactphp/set-http-version
Set protocol version on request creation
2 parents 59bef8b + b500da5 commit cf8ca08

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public function __construct(ConnectorInterface $connector, ConnectorInterface $s
1515
$this->secureConnector = $secureConnector;
1616
}
1717

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

2323
return new Request($connector, $requestData);

src/RequestData.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ class RequestData
77
private $method;
88
private $url;
99
private $headers;
10+
private $protocolVersion;
1011

11-
private $protocolVersion = '1.0';
12-
13-
public function __construct($method, $url, array $headers = [])
12+
public function __construct($method, $url, array $headers = [], $protocolVersion = '1.0')
1413
{
1514
$this->method = $method;
1615
$this->url = $url;
1716
$this->headers = $headers;
17+
$this->protocolVersion = $protocolVersion;
1818
}
1919

2020
private function mergeDefaultheaders(array $headers)

tests/RequestDataTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ public function toStringReturnsHTTPRequestMessageWithProtocolVersion()
3434
$this->assertSame($expected, $requestData->__toString());
3535
}
3636

37+
/** @test */
38+
public function toStringReturnsHTTPRequestMessageWithProtocolVersionThroughConstructor()
39+
{
40+
$requestData = new RequestData('GET', 'http://www.example.com', [], '1.1');
41+
42+
$expected = "GET / HTTP/1.1\r\n" .
43+
"Host: www.example.com\r\n" .
44+
"User-Agent: React/alpha\r\n" .
45+
"Connection: close\r\n" .
46+
"\r\n";
47+
48+
$this->assertSame($expected, $requestData->__toString());
49+
}
50+
3751
/** @test */
3852
public function toStringUsesUserPassFromURL()
3953
{

0 commit comments

Comments
 (0)