Skip to content

Support BinaryFileResponse and custom streaming response classes. #132

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 4 commits into from
Aug 29, 2018

Conversation

mathieudz
Copy link
Contributor

Custom streaming response classes must return false on getContent(), just like StreamingResponse and BinaryFileResponse do.
The responses aren't streamed yet though.

@@ -290,7 +289,8 @@ protected function mapResponse(SymfonyResponse $syResponse, $stdout='')

// get contents
ob_start();
if ($syResponse instanceof SymfonyStreamedResponse) {
$content = $syResponse->getContent();
if ($content === false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test case where the kernel returns a StreamedResponse to ensure the old functionality works as expected?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm, got it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also how does it handle other types of responses without content? e.g. RedirectResponse? I think we definitely need test cases with some different types of responses to make sure this works as expected.

Copy link
Contributor Author

@mathieudz mathieudz Aug 28, 2018

Choose a reason for hiding this comment

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

Responses without content return null so that would be fine.
Actually, the logic for streamed responses will also work for non-streamed response, because that's what Symfony does in index.php: only send() is used, not getContents(). Maybe we could just always call sendContent() and work with the output buffers? Then php-pm doesn't have to know about specific kinds of responses.
From the default index.php:

$response = $kernel->handle($request);
$response->send();

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea - I like it! There is no reason the HttpKernel needs to distinguish between response types, it just needs to buffer the content. Its also a step in the right direction if we want to implement real streamed responses later I think.

@mathieudz
Copy link
Contributor Author

mathieudz commented Aug 28, 2018

Updated PR to handle responses (streamed or not) like Symfony does.

@andig
Copy link
Contributor

andig commented Aug 29, 2018

Please check the cs findings

@andig andig merged commit 6c91cdd into php-pm:master Aug 29, 2018
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.

3 participants