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

Refactor Lambda response streaming. #696

Merged
merged 3 commits into from
Sep 15, 2023
Merged

Conversation

bnusunny
Copy link
Contributor

Remove the separate streaming.rs from lambda-runtime crate. Merge into the run method.

Added FunctionResponse enum to capture both buffered response and streaming response.

Added IntoFunctionResponse trait to convert Serialize response into FunctionResponse::BufferedResponse, and convert Stream response into FunctionResponse::StreamingResponse. Existing handler functions should continue to work.

Improved error handling in response streaming. Return trailers to report errors instead of panic.

By submitting this pull request

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I confirm that I've made a best effort attempt to update all relevant documentation.

Remove the separate streaming.rs from lambda-runtime crate. Merge into the `run` method.

Added FunctionResponse enum to capture both buffered response and streaming response.

Added IntoFunctionResponse trait to convert `Serialize` response into FunctionResponse::BufferedResponse, and convert `Stream` response into FunctionResponse::StreamingResponse. Existing handler functions should continue to work.

Improved error handling in response streaming. Return trailers to report errors instead of panic.
@bnusunny bnusunny requested a review from calavera September 14, 2023 16:34

req_headers.insert("Transfer-Encoding", "chunked".parse()?);
req_headers.insert("Lambda-Runtime-Function-Response-Mode", "streaming".parse()?);
req_headers.append("Trailer", "Lambda-Runtime-Function-Error-Type".parse()?);
Copy link
Contributor

@calavera calavera Sep 14, 2023

Choose a reason for hiding this comment

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

can you leave a comment explaining what these Trailer headers are for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

great, thanks!

@calavera
Copy link
Contributor

This looks good at first glance. I'm going to run some tests today before merging it.

Copy link
Contributor

@calavera calavera left a comment

Choose a reason for hiding this comment

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

Looks good. Awesome refactor @bnusunny !

@calavera calavera merged commit cf72bb0 into main Sep 15, 2023
7 checks passed
@calavera calavera deleted the refactor_response_streaming branch September 15, 2023 02:46
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.

2 participants