Skip to content

[HttpKernel] Why are StreamedResponse's sent by a kernel.response listener? #13591

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
gerryvdm opened this issue Feb 4, 2015 · 6 comments
Closed

Comments

@gerryvdm
Copy link

gerryvdm commented Feb 4, 2015

I was wondering what the exact use of the StreamedResponseListener in the HttpKernel is, since responses are typically sent to the browser anyway by invoking Response::send() in the front controller.

Maybe this event subscriber can be eliminated? Or what are the use-cases?

@ogizanagi
Copy link
Contributor

Might be wrong, or incomplete, but I think this is to avoid triggering some of the other KernelEvents::RESPONSE listeners like esi, profiler, ... before sending the Response to the client.

As you can see, the priority is set to -1024, and the Response is sent inside the Listener. Which means that any other listener will not have any effect if its priority is over -1024.
So no, it could not be removed.

@gerryvdm
Copy link
Author

gerryvdm commented Feb 4, 2015

Not sure I understand @ogizanagi, every kernel.response listener with a priority > -1024 (I assume most if not all) is executed before the StreamedResponseListener.

@ogizanagi
Copy link
Contributor

Right. My assumptions were biased as I inverted the priority. Forget what I said :)

The right answer is here : #2935 (comment)

@stof
Copy link
Member

stof commented Aug 1, 2015

The response is send by the listener so that the callback is triggered before leaving the request scope, i.e. before leaving the Kernel::handle() call.

@javiereguiluz
Copy link
Member

I think it's safe to close the issue. @gerryvdm's question is answered in #2935 (comment) and it seems like there's nothing else to do.

@stof stof closed this as completed Sep 3, 2015
@TomaszGasior
Copy link

TomaszGasior commented Jul 11, 2020

@stof @fabpot

The response is send by the listener so that the callback is triggered before leaving the request scope, i.e. before leaving the Kernel::handle() call.

Could you please tell me why is this important at all? Why is that important to trigger callback in Kernel::handle() instead of in send() method in front controller? What's the difference at all? StreamedResponse works exactly the same without this listener and the listener breaks compatibility with tests.

Here, in 2020 with Symfony 4.*, I tried to write tests for request which returns streamed response with PDF document. Wich StreamedResponseListener my terminal is polluted with binary contents. With StreamedResponseListener disabled response of the web application works exactly the same.

The existence of StreamedResponseListener causes two negative things for tests:

  • Output of reponse pollutes terminal.
  • You can't get content of response from test.

So basically what's the difference? Can't we disable StreamedResponseListener, at least for tests?


You can work around the problem using services_test.yaml with:

services:
    streamed_response_listener:
        class: Symfony\Component\HttpKernel\EventListener\StreamedResponseListener
        tags: ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants