[HttpFoundation] Fixed Request::getPort returns incorrect value under IPv6
Fixed issue with Request::getPort method returning an incorrect value when the HTTP_HOST header is a IPv6 address.
This commit is contained in:
parent
185aafadd0
commit
2a0e8e39b8
@ -932,7 +932,13 @@ class Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($host = $this->headers->get('HOST')) {
|
if ($host = $this->headers->get('HOST')) {
|
||||||
if (false !== $pos = strrpos($host, ':')) {
|
if ($host[0] === '[') {
|
||||||
|
$pos = strpos($host, ':', strrpos($host, ']'));
|
||||||
|
} else {
|
||||||
|
$pos = strrpos($host, ':');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false !== $pos) {
|
||||||
return intval(substr($host, $pos + 1));
|
return intval(substr($host, $pos + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +163,14 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(90, $request->getPort());
|
$this->assertEquals(90, $request->getPort());
|
||||||
$this->assertTrue($request->isSecure());
|
$this->assertTrue($request->isSecure());
|
||||||
|
|
||||||
|
$request = Request::create('https://[::1]/foo');
|
||||||
|
$this->assertEquals('https://[::1]/foo', $request->getUri());
|
||||||
|
$this->assertEquals('/foo', $request->getPathInfo());
|
||||||
|
$this->assertEquals('[::1]', $request->getHost());
|
||||||
|
$this->assertEquals('[::1]', $request->getHttpHost());
|
||||||
|
$this->assertEquals(443, $request->getPort());
|
||||||
|
$this->assertTrue($request->isSecure());
|
||||||
|
|
||||||
$json = '{"jsonrpc":"2.0","method":"echo","id":7,"params":["Hello World"]}';
|
$json = '{"jsonrpc":"2.0","method":"echo","id":7,"params":["Hello World"]}';
|
||||||
$request = Request::create('http://example.com/jsonrpc', 'POST', array(), array(), array(), array(), $json);
|
$request = Request::create('http://example.com/jsonrpc', 'POST', array(), array(), array(), array(), $json);
|
||||||
$this->assertEquals($json, $request->getContent());
|
$this->assertEquals($json, $request->getContent());
|
||||||
|
Reference in New Issue
Block a user