diff --git a/src/Io/RequestHeaderParser.php b/src/Io/RequestHeaderParser.php index 5125c77f..64b5dcdb 100644 --- a/src/Io/RequestHeaderParser.php +++ b/src/Io/RequestHeaderParser.php @@ -168,6 +168,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'; } @@ -230,8 +231,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) @@ -244,6 +245,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 @@ -266,9 +273,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 0dde7a0c..0311304e 100644 --- a/tests/Io/StreamingServerTest.php +++ b/tests/Io/StreamingServerTest.php @@ -211,7 +211,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); @@ -223,6 +223,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; @@ -278,7 +313,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) { @@ -297,10 +332,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) { @@ -319,10 +354,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) { @@ -341,7 +376,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() @@ -416,7 +451,7 @@ public function testRequestAbsoluteEvent() $this->assertSame('example.com', $requestAssertion->getHeaderLine('Host')); } - public function testRequestAbsoluteAddsMissingHostEvent() + public function testRequestAbsoluteNonMatchingHostWillBePassedAsIs() { $requestAssertion = null; @@ -427,37 +462,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() @@ -516,7 +541,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"; @@ -536,7 +561,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"; @@ -955,7 +980,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\n\r\nfoo", $buffer); @@ -990,7 +1015,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\n\r\nfoo", $buffer); @@ -1028,7 +1053,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); @@ -1066,7 +1091,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'); @@ -1418,7 +1443,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"; @@ -1447,7 +1472,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"; @@ -1477,7 +1502,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"; @@ -1506,7 +1531,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"; @@ -1535,7 +1560,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"; @@ -1564,7 +1589,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"; @@ -1593,7 +1618,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"; @@ -1622,7 +1647,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"; @@ -1654,7 +1679,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"; @@ -1680,7 +1705,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"; @@ -1707,7 +1732,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"; @@ -1733,7 +1758,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"; @@ -1757,7 +1782,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"; @@ -1779,7 +1804,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"; @@ -1802,7 +1827,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"; @@ -1824,7 +1849,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"; @@ -2221,7 +2246,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"; @@ -2744,7 +2769,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"; @@ -2765,7 +2790,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"; @@ -2786,7 +2811,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"; @@ -2805,7 +2830,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"; @@ -3009,7 +3034,7 @@ public function testNewConnectionWillInvokeParserTwiceAfterInvokingRequestHandle 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";