Skip to content
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

JavaClient can stream the HTTP response body #1005

Conversation

alex-james-dev
Copy link
Contributor

@alex-james-dev alex-james-dev commented Aug 11, 2023

Make java_http stream the HTTP response body one byte at a time. Currently, java_http
gets all the bytes of the HTTP response body and then creates a stream from these bytes.

  • Use Isolate.spawn instead of Isolate.run so that we can send more than one message from the worker isolate.

  • Make the worker isolate send the HTTP response status code, reason phrase and response headers (in that order) to the main isolate.

  • The rest of the messages from the worker isolate are the HTTP response body bytes. Create the response body stream from these bytes.

  • Handle the worker isolate sending ClientException as well as the HTTP response data.

  • Close the worker isolate if there is a ClientException when getting the HTTP response status code.

  • Make java_http pass testResponseBodyStreamed in package:http_client_conformance_tests.

Relevant tracking issue: #957.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@brianquinlan
Copy link
Collaborator

Is this ready for review?

@alex-james-dev
Copy link
Contributor Author

alex-james-dev commented Aug 15, 2023

Is this ready for review?

Hey @brianquinlan,

There are a couple of ClientExceptions still being thrown inside the worker isolate. But I'm happy to get this PR reviewed/merged and make the extra changes in a separate PR.

In particular:

  • There are some unhandled exceptions occurring inside the worker isolate due to calls to _parseContentLengthHeader(): unhandled exception. I think the tests are still passing because we call _parseContentLengthHeader() in both the main isolate and the worker isolate.

  • We throw a ClientException inside the worker isolate when there is an issue retrieving the status code. I can change it so that the ClientException is sent over the SendPort instead. I don't think we have a test for this yet. I've created a basic test locally to check that the ClientException is being thrown inside the worker isolate.

Thank you!

@alex-james-dev alex-james-dev marked this pull request as ready for review August 15, 2023 21:40
}
} finally {
// TODO: Should we kill the isolate here?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't it exit on it's own?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @brianquinlan,

I think it does exit on its own normally although I'm not 100% sure about when the user cancels the StreamSubscription of the StreamedResponse.stream. But perhaps we don't have to worry too much about this?

@natebosch
Copy link
Member

Can you edit the 1st message in the PR to be a description of the code changes that we can use as the commit message?
See https://google.github.io/eng-practices/review/developer/cl-descriptions.html#informative for more on authoring commit messages ("cl descriptions" in the link).

@brianquinlan brianquinlan changed the title Stream response body JavaClient can stream the HTTP response body Aug 15, 2023
@alex-james-dev
Copy link
Contributor Author

Hey @natebosch,

I've updated the 1st message in the PR. Thanks for the link, it was very helpful and I've bookmarked it for future reference 🔖.

Thank you!

@brianquinlan brianquinlan merged commit 58a5462 into dart-lang:master Aug 17, 2023
15 checks passed
@alex-james-dev alex-james-dev deleted the java-http-stream-response-body-one-byte-at-a-time branch August 17, 2023 18:30
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