[HttpKernel] Turn bad hosts into 400 instead of 500
This commit is contained in:
parent
fad59b3ce7
commit
3e47c71028
@ -15,6 +15,7 @@ use Psr\Log\LoggerInterface;
|
|||||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||||
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
|
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
@ -96,7 +97,11 @@ class RouterListener implements EventSubscriberInterface
|
|||||||
private function setCurrentRequest(Request $request = null)
|
private function setCurrentRequest(Request $request = null)
|
||||||
{
|
{
|
||||||
if (null !== $request && $this->request !== $request) {
|
if (null !== $request && $this->request !== $request) {
|
||||||
|
try {
|
||||||
$this->context->fromRequest($request);
|
$this->context->fromRequest($request);
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
throw new BadRequestHttpException($e->getMessage(), $e, $e->getCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
@ -155,4 +155,19 @@ class RouterListenerTest extends TestCase
|
|||||||
array(array(), 'Matched route "n/a".'),
|
array(array(), 'Matched route "n/a".'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
|
||||||
|
*/
|
||||||
|
public function testSubRequestWithBadHost()
|
||||||
|
{
|
||||||
|
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||||
|
$request = Request::create('http://bad host %22/');
|
||||||
|
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
|
||||||
|
|
||||||
|
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
|
||||||
|
|
||||||
|
$listener = new RouterListener($requestMatcher, new RequestContext(), null, $this->requestStack);
|
||||||
|
$listener->onKernelRequest($event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user