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
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 0 additions & 5 deletions UPGRADE-6.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ FrameworkBundle
To prevent services resetting after each message the "--no-reset" option in "messenger:consume" command can be set
* Deprecate not setting the `http_method_override` config option. The default value will change to `false` in 7.0.

HttpKernel
----------

* Deprecate StreamedResponseListener, it's not needed anymore

Routing
-------

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Symfony\Component\HttpKernel\EventListener\ErrorListener;
use Symfony\Component\HttpKernel\EventListener\LocaleListener;
use Symfony\Component\HttpKernel\EventListener\ResponseListener;
use Symfony\Component\HttpKernel\EventListener\StreamedResponseListener;
use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener;

return static function (ContainerConfigurator $container) {
Expand Down Expand Up @@ -104,6 +105,9 @@
])
->tag('kernel.event_subscriber')

->set('streamed_response_listener', StreamedResponseListener::class)
->tag('kernel.event_subscriber')

->set('locale_listener', LocaleListener::class)
->args([
service('request_stack'),
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ CHANGELOG

* Add `BackedEnumValueResolver` to resolve backed enum cases from request attributes in controller arguments
* Add `DateTimeValueResolver` to resolve request attributes into DateTime objects in controller arguments
* Deprecate StreamedResponseListener, it's not needed anymore
* Add `Profiler::isEnabled()` so collaborating collector services may elect to omit themselves
* Add the `UidValueResolver` argument value resolver
* Add `AbstractBundle` class for DI configuration/definition on a single file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => ['onKernelRequest', 128],
// low priority to come after regular response listeners
// low priority to come after regular response listeners, but higher than StreamedResponseListener
KernelEvents::RESPONSE => ['onKernelResponse', -1000],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

trigger_deprecation('symfony/http-kernel', '6.1', 'The "%s" class is deprecated.', StreamedResponseListener::class);

/**
* StreamedResponseListener is responsible for sending the Response
* to the client.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final
*
* @deprecated since Symfony 6.1
*/
class StreamedResponseListener implements EventSubscriberInterface
{
Expand Down
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