8000 [HttpFoundation] Warning when request has both Forwarded and X-Forwarded-For by magnusnordlander · Pull Request #18688 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Closed
Prev Previous commit
Next Next commit
Renamed listener and CS fixes.
  • Loading branch information
magnusnordlander committed Jun 28, 2016
commit 66f19f12cb450f22d7092ee085587bdd2371abf7
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<tag name="kernel.event_subscriber" />
</service>

<service id="validate_request_client_ip_listener" class="Symfony\Component\HttpKernel\EventListener\ValidateRequestClientIpListener">
<service id="validate_request_listener" class="Symfony\Component\HttpKernel\EventListener\ValidateRequestListener">
<tag name="kernel.event_subscriber" />
</service>
</services>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand All @@ -24,7 +23,7 @@
*
* @author Magnus Nordlander <magnus@fervo.se>
*/
class ValidateRequestClientIpListener implements EventSubscriberInterface
class ValidateRequestListener implements EventSubscriberInterface
{
/**
* Performs the validation.
Expand All @@ -33,12 +32,12 @@ class ValidateRequestClientIpListener implements EventSubscriberInterface
*/
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
if ($event->isMasterRequest()) {
try {
// This will throw an exception if the headers are inconsistent.
$event->getRequest()->getClientIps();
} catch (ConflictingHeadersException $e) {
throw new HttpException(400, 'The request headers contain conflicting information regarding the origin of this request.', $e);
throw new BadRequestHttpException('The request headers contain conflicting information regarding the origin of this request.', $e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\EventListener\ValidateRequestClientIpListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;

class ValidateRequestClientIpTest extends \PHPUnit_Framework_TestCase
class ValidateRequestListenerTest extends \PHPUnit_Framework_TestCase
{
public function testListenerThrowsOnInconsistentMasterRequests()
public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
Expand All @@ -37,7 +36,7 @@ public function testListenerThrowsOnInconsistentMasterRequests()
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
}

public function testListenerDoesNothingOnConsistentRequests()
public function testListenerDoesNothingOnValidRequests()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
Expand Down
0