Skip to content

Add support for streamed response #50

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

Merged
merged 1 commit into from
Mar 11, 2019

Conversation

danizord
Copy link

@danizord danizord commented Sep 26, 2018

Here's a simple implementation of response streaming heavily inspired by Diactoros' response emitter, using HttpFoundation's StreamedResponse. It lacks support for Content-Range, but I can provide that in a future PR.

Closes https://github.com/symfony/psr-http-message-bridge/issues/3

@danizord
Copy link
Author

It seems like Travis is happy but fabbot.io failed with "Not Found" 🤔

@danizord
Copy link
Author

danizord commented Nov 14, 2018

Ping @stof @fabpot @dunglas in case you missed it 😄

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, can you just run PHP CS Fixer please.

@danizord
Copy link
Author

@dunglas done :)

@@ -140,11 +154,12 @@ protected function getTemporaryPath()
*/
public function createResponse(ResponseInterface $psrResponse)
{
$response = new Response(
$psrResponse->getBody()->__toString(),
$response = new StreamedResponse(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use stream responses in every possible cases because StreamedResponse have some downsides like preventing the debug toolbar from being injected.

Can this be made configurable ?

@jdecool
Copy link

jdecool commented Feb 21, 2019

What about this PR ?

Is it still relevant ? This is a nice feature to add in this component.

@danizord
Copy link
Author

danizord commented Feb 21, 2019

Hey @jdecool! @jvasseur suggested to make it configurable, but I'm not sure how 🤔

Any suggestions?

@jdecool
Copy link

jdecool commented Feb 21, 2019

Maybe by creating a another method ?

Don't touch createResponse method and add a new createStreamedResponse ?

@jdecool
Copy link

jdecool commented Feb 24, 2019

@danizord do you need help to finish this PR ?

@nicolas-grekas nicolas-grekas force-pushed the feature/streamed-response branch from 0c60565 to 013db27 Compare March 11, 2019 15:58
@nicolas-grekas nicolas-grekas force-pushed the feature/streamed-response branch from 013db27 to 7cc1605 Compare March 11, 2019 15:59
@nicolas-grekas
Copy link
Member

I rebased the PR and made the behavior opt-in by adding a new bool $streamed argument to createResponse()

@nicolas-grekas
Copy link
Member

Thank you @danizord.

@nicolas-grekas nicolas-grekas merged commit 7cc1605 into symfony:master Mar 11, 2019
nicolas-grekas added a commit that referenced this pull request Mar 11, 2019
This PR was merged into the 1.2-dev branch.

Discussion
----------

Add support for streamed response

Here's a simple implementation of response streaming heavily inspired by Diactoros' response emitter, using HttpFoundation's `StreamedResponse`. It lacks support for `Content-Range`, but I can provide that in a future PR.

Closes https://github.com/symfony/psr-http-message-bridge/issues/3

Commits
-------

7cc1605 Add support for streamed response
@danizord danizord deleted the feature/streamed-response branch March 11, 2019 19:09
@danizord danizord restored the feature/streamed-response branch March 11, 2019 19:10
nicolas-grekas added a commit that referenced this pull request Nov 25, 2019
This PR was squashed before being merged into the 1.2-dev branch.

Discussion
----------

Add support for streamed Symfony request

As a continuation of #3 and #50 . Add support for converting a `ServerRequestInterface` with a large body to a Symfony request.

I'm not all too familiar with Symfony components, but I saw that a Symfony request supports `string|resource|null` as its body. Since calling `detach()` on a `StreamInterface` will make the stream unsuable I added a `$streamed` argument to the function in order to not make break any existing code, and to make it a conscious decision of the caller to stream the response.

I'm happy to make any necessary changes if needed.

Commits
-------

df26630 Add support for streamed Symfony request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants