[HttpFoundation] Fixed Request::create handling of full URIs
This commit is contained in:
parent
beecd1fef8
commit
fb41389999
@ -144,7 +144,15 @@ class Request
|
||||
'SCRIPT_FILENAME' => '',
|
||||
);
|
||||
|
||||
if (in_array(strtolower($method), array('post', 'put', 'delete'))) {
|
||||
$components = parse_url($uri);
|
||||
if (isset($components['host'])) {
|
||||
$defaults['HTTP_HOST'] = $components['host'];
|
||||
}
|
||||
if (isset($components['port'])) {
|
||||
$defaults['SERVER_PORT'] = $components['port'];
|
||||
}
|
||||
|
||||
if (in_array(strtoupper($method), array('POST', 'PUT', 'DELETE'))) {
|
||||
$request = $parameters;
|
||||
$query = array();
|
||||
$defaults['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
|
||||
@ -159,12 +167,14 @@ class Request
|
||||
}
|
||||
}
|
||||
|
||||
$queryString = false !== ($pos = strpos($uri, '?')) ? html_entity_decode(substr($uri, $pos + 1)) : '';
|
||||
$queryString = isset($components['query']) ? html_entity_decode($components['query']) : '';
|
||||
parse_str($queryString, $qs);
|
||||
if (is_array($qs)) {
|
||||
$query = array_replace($qs, $query);
|
||||
}
|
||||
|
||||
$uri = $components['path'] . ($queryString ? '?'.$queryString : '');
|
||||
|
||||
$server = array_replace($defaults, $server, array(
|
||||
'REQUEST_METHOD' => strtoupper($method),
|
||||
'PATH_INFO' => '',
|
||||
|
@ -44,6 +44,23 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('bar', $request->headers->get('FOO'), '->initialize() takes an array of HTTP headers as its fourth argument');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\HttpFoundation\Request::create
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
$request = Request::create('http://test.com/foo?bar=baz');
|
||||
$this->assertEquals('http://test.com:80/foo?bar=baz', $request->getUri());
|
||||
$this->assertEquals('/foo', $request->getPathInfo());
|
||||
$this->assertEquals('bar=baz', $request->getQueryString());
|
||||
|
||||
$request = Request::create('test.com:90/foo');
|
||||
$this->assertEquals('http://test.com:90/foo', $request->getUri());
|
||||
$this->assertEquals('/foo', $request->getPathInfo());
|
||||
$this->assertEquals('test.com', $request->getHost());
|
||||
$this->assertEquals(90, $request->getPort());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\HttpFoundation\Request::duplicate
|
||||
*/
|
||||
|
Reference in New Issue
Block a user