Skip to content

[HttpKernel] Revert #45476 to fix missing Request in RequestStack for StreamedResponse #51391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[HttpKernel] Add test to ensure Request being there while StreamedRes…
…ponse
  • Loading branch information
DaDeather committed Aug 15, 2023
commit 97ed88709472f3d25e03e3eca5187f2e17154a40
36 changes: 36 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
Expand Down Expand Up @@ -477,6 +478,34 @@ public function testInconsistentClientIpsOnMainRequests()
Request::setTrustedProxies([], -1);
}

public function testVerifyRequestStackPushPopCallOrderDuringHandle()
{
$request = new Request();
$stack = new RequestStack();
$dispatcher = new EventDispatcher();
$kernel = $this->getHttpKernel($dispatcher, null, $stack);

$response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST);
self::assertNull($stack->getMainRequest());
$response->send();
self::assertNull($stack->getMainRequest());
}

public function testVerifyRequestStackPushPopWithStreamedResponse()
{
$request = new Request();
$stack = new RequestStack();
$dispatcher = new EventDispatcher();
$kernel = $this->getHttpKernel($dispatcher, [new TestController(), 'streamedResponseController'], $stack);

$response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST);
self::assertNotNull($stack->getMainRequest());
ob_start();
$response->send();
self::assertSame('foo', ob_get_clean());
self::assertNull($stack->getMainRequest());
}

private function getHttpKernel(EventDispatcherInterface $eventDispatcher, $controller = null, RequestStack $requestStack = null, array $arguments = [], bool $handleAllThrowables = false)
{
$controller ??= fn () => new Response('Hello');
Expand Down Expand Up @@ -515,6 +544,13 @@ public function controller()
return new Response('foo');
}

public function streamedResponseController()
{
return new StreamedResponse(function () {
echo 'foo';
});
}

public static function staticController()
{
return new Response('foo');
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy