From a333f46072b92e976e2d0b8c7e7194323cd389b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Thu, 3 Sep 2015 15:39:02 +0200 Subject: [PATCH] Support explicitly using HTTP/1.1 protocol version Still defaults to HTTP/1.0 and offers only limited support --- src/Request.php | 1 - src/RequestData.php | 2 +- tests/RequestDataTest.php | 17 +++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Request.php b/src/Request.php index a2f7024..fa64106 100644 --- a/src/Request.php +++ b/src/Request.php @@ -68,7 +68,6 @@ function ($stream) use ($requestData, &$streamRef, &$stateRef) { $stream->on('end', array($this, 'handleEnd')); $stream->on('error', array($this, 'handleError')); - $requestData->setProtocolVersion('1.0'); $headers = (string) $requestData; $stream->write($headers); diff --git a/src/RequestData.php b/src/RequestData.php index d2a3e1f..2d379aa 100644 --- a/src/RequestData.php +++ b/src/RequestData.php @@ -8,7 +8,7 @@ class RequestData private $url; private $headers; - private $protocolVersion = '1.1'; + private $protocolVersion = '1.0'; public function __construct($method, $url, array $headers = []) { diff --git a/tests/RequestDataTest.php b/tests/RequestDataTest.php index c6a3e58..7fbeb55 100644 --- a/tests/RequestDataTest.php +++ b/tests/RequestDataTest.php @@ -11,6 +11,20 @@ public function toStringReturnsHTTPRequestMessage() { $requestData = new RequestData('GET', 'http://www.example.com'); + $expected = "GET / HTTP/1.0\r\n" . + "Host: www.example.com\r\n" . + "User-Agent: React/alpha\r\n" . + "\r\n"; + + $this->assertSame($expected, $requestData->__toString()); + } + + /** @test */ + public function toStringReturnsHTTPRequestMessageWithProtocolVersion() + { + $requestData = new RequestData('GET', 'http://www.example.com'); + $requestData->setProtocolVersion('1.1'); + $expected = "GET / HTTP/1.1\r\n" . "Host: www.example.com\r\n" . "User-Agent: React/alpha\r\n" . @@ -25,10 +39,9 @@ public function toStringUsesUserPassFromURL() { $requestData = new RequestData('GET', 'http://john:dummy@www.example.com'); - $expected = "GET / HTTP/1.1\r\n" . + $expected = "GET / HTTP/1.0\r\n" . "Host: www.example.com\r\n" . "User-Agent: React/alpha\r\n" . - "Connection: close\r\n" . "Authorization: Basic am9objpkdW1teQ==\r\n" . "\r\n";