diff --git a/src/Io/RequestHeaderParser.php b/src/Io/RequestHeaderParser.php index 53f7ff09..2c9b121c 100644 --- a/src/Io/RequestHeaderParser.php +++ b/src/Io/RequestHeaderParser.php @@ -172,6 +172,7 @@ public function parseRequest($headers, $remoteSocketUri, $localSocketUri) } // default host if unset comes from local socket address or defaults to localhost + $hasHost = $host !== null; if ($host === null) { $host = isset($localParts['host'], $localParts['port']) ? $localParts['host'] . ':' . $localParts['port'] : '127.0.0.1'; } @@ -234,8 +235,8 @@ public function parseRequest($headers, $remoteSocketUri, $localSocketUri) $request = $request->withRequestTarget($start['target']); } - // Optional Host header value MUST be valid (host and optional port) - if ($request->hasHeader('Host')) { + if ($hasHost) { + // Optional Host request header value MUST be valid (host and optional port) $parts = \parse_url('http://' . $request->getHeaderLine('Host')); // make sure value contains valid host component (IP or hostname) @@ -248,6 +249,12 @@ public function parseRequest($headers, $remoteSocketUri, $localSocketUri) if ($parts === false || $parts) { throw new \InvalidArgumentException('Invalid Host header value'); } + } elseif (!$hasHost && $start['version'] === '1.1' && $start['method'] !== 'CONNECT') { + // require Host request header for HTTP/1.1 (except for CONNECT method) + throw new \InvalidArgumentException('Missing required Host request header'); + } elseif (!$hasHost) { + // remove default Host request header for HTTP/1.0 when not explicitly given + $request = $request->withoutHeader('Host'); } // ensure message boundaries are valid according to Content-Length and Transfer-Encoding request headers @@ -270,9 +277,6 @@ public function parseRequest($headers, $remoteSocketUri, $localSocketUri) } } - // always sanitize Host header because it contains critical routing information - $request = $request->withUri($request->getUri()->withUserInfo('u')->withUserInfo('')); - return $request; } } diff --git a/tests/Io/RequestHeaderParserTest.php b/tests/Io/RequestHeaderParserTest.php index b0a339ed..356443fb 100644 --- a/tests/Io/RequestHeaderParserTest.php +++ b/tests/Io/RequestHeaderParserTest.php @@ -257,7 +257,7 @@ public function testHeaderEventWithShouldApplyDefaultAddressFromLocalConnectionA $connection->emit('data', array("GET /foo HTTP/1.0\r\n\r\n")); $this->assertEquals('http://127.1.1.1:8000/foo', $request->getUri()); - $this->assertEquals('127.1.1.1:8000', $request->getHeaderLine('Host')); + $this->assertFalse($request->hasHeader('Host')); } public function testHeaderEventViaHttpsShouldApplyHttpsSchemeFromLocalTlsConnectionAddress() @@ -550,7 +550,7 @@ public function testInvalidContentLengthRequestHeaderWillEmitError() $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); - $connection->emit('data', array("GET / HTTP/1.1\r\nContent-Length: foo\r\n\r\n")); + $connection->emit('data', array("GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: foo\r\n\r\n")); $this->assertInstanceOf('InvalidArgumentException', $error); $this->assertSame(400, $error->getCode()); @@ -570,7 +570,7 @@ public function testInvalidRequestWithMultipleContentLengthRequestHeadersWillEmi $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); - $connection->emit('data', array("GET / HTTP/1.1\r\nContent-Length: 4\r\nContent-Length: 5\r\n\r\n")); + $connection->emit('data', array("GET / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 4\r\nContent-Length: 5\r\n\r\n")); $this->assertInstanceOf('InvalidArgumentException', $error); $this->assertSame(400, $error->getCode()); @@ -590,7 +590,7 @@ public function testInvalidTransferEncodingRequestHeaderWillEmitError() $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); - $connection->emit('data', array("GET / HTTP/1.1\r\nTransfer-Encoding: foo\r\n\r\n")); + $connection->emit('data', array("GET / HTTP/1.1\r\nHost: localhost\r\nTransfer-Encoding: foo\r\n\r\n")); $this->assertInstanceOf('InvalidArgumentException', $error); $this->assertSame(501, $error->getCode()); @@ -610,7 +610,7 @@ public function testInvalidRequestWithBothTransferEncodingAndContentLengthWillEm $connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(null)->getMock(); $parser->handle($connection); - $connection->emit('data', array("GET / HTTP/1.1\r\nTransfer-Encoding: chunked\r\nContent-Length: 0\r\n\r\n")); + $connection->emit('data', array("GET / HTTP/1.1\r\nHost: localhost\r\nTransfer-Encoding: chunked\r\nContent-Length: 0\r\n\r\n")); $this->assertInstanceOf('InvalidArgumentException', $error); $this->assertSame(400, $error->getCode()); @@ -762,7 +762,7 @@ public function testQueryParmetersWillBeSet() private function createGetRequest() { $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "\r\n"; @@ -772,7 +772,7 @@ private function createGetRequest() private function createAdvancedPostRequest() { $data = "POST /foo?bar=baz HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "User-Agent: react/alpha\r\n"; $data .= "Connection: close\r\n"; $data .= "\r\n"; diff --git a/tests/Io/StreamingServerTest.php b/tests/Io/StreamingServerTest.php index d2401a06..c771330b 100644 --- a/tests/Io/StreamingServerTest.php +++ b/tests/Io/StreamingServerTest.php @@ -210,7 +210,7 @@ public function testRequestGetWithHostAndDefaultPortWillBeIgnored() $server->listen($this->socket); $this->socket->emit('connection', array($this->connection)); - $data = "GET / HTTP/1.1\r\nHost: example.com:80\r\n\r\n"; + $data = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"; $this->connection->emit('data', array($data)); $this->assertInstanceOf('RingCentral\Psr7\Request', $requestAssertion); @@ -222,6 +222,41 @@ public function testRequestGetWithHostAndDefaultPortWillBeIgnored() $this->assertSame('example.com', $requestAssertion->getHeaderLine('Host')); } + public function testRequestGetHttp10WithoutHostWillBeIgnored() + { + $requestAssertion = null; + $server = new StreamingServer(Factory::create(), function (ServerRequestInterface $request) use (&$requestAssertion) { + $requestAssertion = $request; + }); + + $server->listen($this->socket); + $this->socket->emit('connection', array($this->connection)); + + $data = "GET / HTTP/1.0\r\n\r\n"; + $this->connection->emit('data', array($data)); + + $this->assertInstanceOf('RingCentral\Psr7\Request', $requestAssertion); + $this->assertSame('GET', $requestAssertion->getMethod()); + $this->assertSame('/', $requestAssertion->getRequestTarget()); + $this->assertSame('/', $requestAssertion->getUri()->getPath()); + $this->assertSame('http://127.0.0.1/', (string)$requestAssertion->getUri()); + $this->assertNull($requestAssertion->getUri()->getPort()); + $this->assertEquals('1.0', $requestAssertion->getProtocolVersion()); + $this->assertSame('', $requestAssertion->getHeaderLine('Host')); + } + + public function testRequestGetHttp11WithoutHostWillReject() + { + $server = new StreamingServer(Factory::create(), 'var_dump'); + $server->on('error', $this->expectCallableOnce()); + + $server->listen($this->socket); + $this->socket->emit('connection', array($this->connection)); + + $data = "GET / HTTP/1.1\r\n\r\n"; + $this->connection->emit('data', array($data)); + } + public function testRequestOptionsAsterisk() { $requestAssertion = null; @@ -277,7 +312,7 @@ public function testRequestConnectAuthorityForm() $this->assertSame('example.com:443', $requestAssertion->getHeaderLine('Host')); } - public function testRequestConnectWithoutHostWillBeAdded() + public function testRequestConnectWithoutHostWillBePassesAsIs() { $requestAssertion = null; $server = new StreamingServer(Factory::create(), function (ServerRequestInterface $request) use (&$requestAssertion) { @@ -296,10 +331,10 @@ public function testRequestConnectWithoutHostWillBeAdded() $this->assertSame('', $requestAssertion->getUri()->getPath()); $this->assertSame('http://example.com:443', (string)$requestAssertion->getUri()); $this->assertSame(443, $requestAssertion->getUri()->getPort()); - $this->assertSame('example.com:443', $requestAssertion->getHeaderLine('Host')); + $this->assertFalse($requestAssertion->hasHeader('Host')); } - public function testRequestConnectAuthorityFormWithDefaultPortWillBeIgnored() + public function testRequestConnectAuthorityFormWithDefaultPortWillBePassedAsIs() { $requestAssertion = null; $server = new StreamingServer(Factory::create(), function (ServerRequestInterface $request) use (&$requestAssertion) { @@ -318,10 +353,10 @@ public function testRequestConnectAuthorityFormWithDefaultPortWillBeIgnored() $this->assertSame('', $requestAssertion->getUri()->getPath()); $this->assertSame('http://example.com', (string)$requestAssertion->getUri()); $this->assertNull($requestAssertion->getUri()->getPort()); - $this->assertSame('example.com', $requestAssertion->getHeaderLine('Host')); + $this->assertSame('example.com:80', $requestAssertion->getHeaderLine('Host')); } - public function testRequestConnectAuthorityFormNonMatchingHostWillBeOverwritten() + public function testRequestConnectAuthorityFormNonMatchingHostWillBePassedAsIs() { $requestAssertion = null; $server = new StreamingServer(Factory::create(), function (ServerRequestInterface $request) use (&$requestAssertion) { @@ -340,7 +375,7 @@ public function testRequestConnectAuthorityFormNonMatchingHostWillBeOverwritten( $this->assertSame('', $requestAssertion->getUri()->getPath()); $this->assertSame('http://example.com', (string)$requestAssertion->getUri()); $this->assertNull($requestAssertion->getUri()->getPort()); - $this->assertSame('example.com', $requestAssertion->getHeaderLine('Host')); + $this->assertSame('other.example.org', $requestAssertion->getHeaderLine('Host')); } public function testRequestConnectOriginFormRequestTargetWillReject() @@ -415,7 +450,7 @@ public function testRequestAbsoluteEvent() $this->assertSame('example.com', $requestAssertion->getHeaderLine('Host')); } - public function testRequestAbsoluteAddsMissingHostEvent() + public function testRequestAbsoluteNonMatchingHostWillBePassedAsIs() { $requestAssertion = null; @@ -426,37 +461,27 @@ public function testRequestAbsoluteAddsMissingHostEvent() $server->listen($this->socket); $this->socket->emit('connection', array($this->connection)); - $data = "GET http://example.com:8080/test HTTP/1.0\r\n\r\n"; + $data = "GET http://example.com/test HTTP/1.1\r\nHost: other.example.org\r\n\r\n"; $this->connection->emit('data', array($data)); $this->assertInstanceOf('RingCentral\Psr7\Request', $requestAssertion); $this->assertSame('GET', $requestAssertion->getMethod()); - $this->assertSame('http://example.com:8080/test', $requestAssertion->getRequestTarget()); - $this->assertEquals('http://example.com:8080/test', $requestAssertion->getUri()); + $this->assertSame('http://example.com/test', $requestAssertion->getRequestTarget()); + $this->assertEquals('http://example.com/test', $requestAssertion->getUri()); $this->assertSame('/test', $requestAssertion->getUri()->getPath()); - $this->assertSame('example.com:8080', $requestAssertion->getHeaderLine('Host')); + $this->assertSame('other.example.org', $requestAssertion->getHeaderLine('Host')); } - public function testRequestAbsoluteNonMatchingHostWillBeOverwritten() + public function testRequestAbsoluteWithoutHostWillReject() { - $requestAssertion = null; - - $server = new StreamingServer(Factory::create(), function (ServerRequestInterface $request) use (&$requestAssertion) { - $requestAssertion = $request; - }); + $server = new StreamingServer(Factory::create(), $this->expectCallableNever()); + $server->on('error', $this->expectCallableOnce()); $server->listen($this->socket); $this->socket->emit('connection', array($this->connection)); - $data = "GET http://example.com/test HTTP/1.1\r\nHost: other.example.org\r\n\r\n"; + $data = "GET http://example.com:8080/test HTTP/1.1\r\n\r\n"; $this->connection->emit('data', array($data)); - - $this->assertInstanceOf('RingCentral\Psr7\Request', $requestAssertion); - $this->assertSame('GET', $requestAssertion->getMethod()); - $this->assertSame('http://example.com/test', $requestAssertion->getRequestTarget()); - $this->assertEquals('http://example.com/test', $requestAssertion->getUri()); - $this->assertSame('/test', $requestAssertion->getUri()->getPath()); - $this->assertSame('example.com', $requestAssertion->getHeaderLine('Host')); } public function testRequestOptionsAsteriskEvent() @@ -515,7 +540,7 @@ public function testRequestPauseWillBeForwardedToConnection() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Content-Length: 5\r\n"; $data .= "\r\n"; @@ -535,7 +560,7 @@ public function testRequestResumeWillBeForwardedToConnection() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Content-Length: 5\r\n"; $data .= "\r\n"; @@ -954,7 +979,7 @@ function ($data) use (&$buffer) { $server->listen($this->socket); $this->socket->emit('connection', array($this->connection)); - $data = "GET / HTTP/1.1\r\n\r\n"; + $data = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"; $this->connection->emit('data', array($data)); $this->assertEquals("HTTP/1.1 200 OK\r\nUpgrade: demo\r\nContent-Length: 3\r\nConnection: close\r\n\r\nfoo", $buffer); @@ -989,7 +1014,7 @@ function ($data) use (&$buffer) { $server->listen($this->socket); $this->socket->emit('connection', array($this->connection)); - $data = "GET / HTTP/1.1\r\nUpgrade: demo\r\n\r\n"; + $data = "GET / HTTP/1.1\r\nHost: localhost\r\nUpgrade: demo\r\n\r\n"; $this->connection->emit('data', array($data)); $this->assertEquals("HTTP/1.1 200 OK\r\nContent-Length: 3\r\nConnection: close\r\n\r\nfoo", $buffer); @@ -1027,7 +1052,7 @@ function ($data) use (&$buffer) { $server->listen($this->socket); $this->socket->emit('connection', array($this->connection)); - $data = "GET / HTTP/1.1\r\nUpgrade: demo\r\n\r\n"; + $data = "GET / HTTP/1.1\r\nHost: localhost\r\nUpgrade: demo\r\n\r\n"; $this->connection->emit('data', array($data)); $this->assertEquals("HTTP/1.1 101 Switching Protocols\r\nUpgrade: demo\r\nConnection: upgrade\r\n\r\nfoo", $buffer); @@ -1065,7 +1090,7 @@ function ($data) use (&$buffer) { $server->listen($this->socket); $this->socket->emit('connection', array($this->connection)); - $data = "GET / HTTP/1.1\r\nUpgrade: demo\r\n\r\n"; + $data = "GET / HTTP/1.1\r\nHost: localhost\r\nUpgrade: demo\r\n\r\n"; $this->connection->emit('data', array($data)); $stream->write('hello'); @@ -1417,7 +1442,7 @@ public function testRequestContentLengthBodyDataWillEmitDataEventOnRequestStream $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Content-Length: 5\r\n"; $data .= "\r\n"; @@ -1446,7 +1471,7 @@ public function testRequestChunkedTransferEncodingRequestWillEmitDecodedDataEven $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Transfer-Encoding: chunked\r\n"; $data .= "\r\n"; @@ -1476,7 +1501,7 @@ public function testRequestChunkedTransferEncodingWithAdditionalDataWontBeEmitte $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Transfer-Encoding: chunked\r\n"; $data .= "\r\n"; @@ -1505,7 +1530,7 @@ public function testRequestChunkedTransferEncodingEmpty() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Transfer-Encoding: chunked\r\n"; $data .= "\r\n"; @@ -1534,7 +1559,7 @@ public function testRequestChunkedTransferEncodingHeaderCanBeUpperCase() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Transfer-Encoding: CHUNKED\r\n"; $data .= "\r\n"; @@ -1563,7 +1588,7 @@ public function testRequestChunkedTransferEncodingCanBeMixedUpperAndLowerCase() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Transfer-Encoding: CHunKeD\r\n"; $data .= "\r\n"; @@ -1592,7 +1617,7 @@ public function testRequestContentLengthWillEmitDataEventAndEndEventAndAdditiona $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Content-Length: 5\r\n"; $data .= "\r\n"; @@ -1621,7 +1646,7 @@ public function testRequestContentLengthWillEmitDataEventAndEndEventAndAdditiona $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Content-Length: 5\r\n"; $data .= "\r\n"; @@ -1653,7 +1678,7 @@ public function testRequestZeroContentLengthWillEmitEndEvent() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Content-Length: 0\r\n"; $data .= "\r\n"; @@ -1679,7 +1704,7 @@ public function testRequestZeroContentLengthWillEmitEndAndAdditionalDataWillBeIg $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Content-Length: 0\r\n"; $data .= "\r\n"; @@ -1706,7 +1731,7 @@ public function testRequestZeroContentLengthWillEmitEndAndAdditionalDataWillBeIg $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Content-Length: 0\r\n"; $data .= "\r\n"; @@ -1732,7 +1757,7 @@ public function testRequestInvalidChunkHeaderTooLongWillEmitErrorOnRequestStream $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Transfer-Encoding: chunked\r\n"; $data .= "\r\n"; @@ -1756,7 +1781,7 @@ public function testRequestInvalidChunkBodyTooLongWillEmitErrorOnRequestStream() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Transfer-Encoding: chunked\r\n"; $data .= "\r\n"; @@ -1778,7 +1803,7 @@ public function testRequestUnexpectedEndOfRequestWithChunkedTransferConnectionWi $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Transfer-Encoding: chunked\r\n"; $data .= "\r\n"; @@ -1801,7 +1826,7 @@ public function testRequestInvalidChunkHeaderWillEmitErrorOnRequestStream() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Transfer-Encoding: chunked\r\n"; $data .= "\r\n"; @@ -1823,7 +1848,7 @@ public function testRequestUnexpectedEndOfRequestWithContentLengthWillEmitErrorO $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Content-Length: 500\r\n"; $data .= "\r\n"; @@ -2220,7 +2245,7 @@ function ($data) use (&$buffer) { $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Expect: 100-continue\r\n"; $data .= "\r\n"; @@ -2743,7 +2768,7 @@ public function testRequestCookieWillBeAddedToServerRequest() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Cookie: hello=world\r\n"; $data .= "\r\n"; @@ -2764,7 +2789,7 @@ public function testRequestInvalidMultipleCookiesWontBeAddedToServerRequest() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Cookie: hello=world\r\n"; $data .= "Cookie: test=failed\r\n"; @@ -2785,7 +2810,7 @@ public function testRequestCookieWithSeparatorWillBeAddedToServerRequest() $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Cookie: hello=world; test=abc\r\n"; $data .= "\r\n"; @@ -2804,7 +2829,7 @@ public function testRequestCookieWithCommaValueWillBeAddedToServerRequest() { $this->socket->emit('connection', array($this->connection)); $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "Cookie: test=abc,def; hello=world\r\n"; $data .= "\r\n"; @@ -2816,7 +2841,7 @@ public function testRequestCookieWithCommaValueWillBeAddedToServerRequest() { private function createGetRequest() { $data = "GET / HTTP/1.1\r\n"; - $data .= "Host: example.com:80\r\n"; + $data .= "Host: example.com\r\n"; $data .= "Connection: close\r\n"; $data .= "\r\n"; diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 84d93eb7..ff2cd9c1 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -269,6 +269,7 @@ private function createPostFileUploadRequest() $data = array(); $data[] = "POST / HTTP/1.1\r\n"; + $data[] = "Host: localhost\r\n"; $data[] = "Content-Type: multipart/form-data; boundary=" . $boundary . "\r\n"; $data[] = "Content-Length: 220\r\n"; $data[] = "\r\n";