Skip to content

Conversation

calavera
Copy link
Contributor

This allows users to force text encoding on responses that the runtime doesn't consider text and would return binary data otherwise.

I thought about adding some kind of configuration, but I think this is more straightforward to help people in cases where we don't return text responses and they would expect text.

Signed-off-by: David Calavera [email protected]

Issue #, if available:

Follow up to #531

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.

This allows users to force text encoding on responses that the runtime doesn't consider text and would return binary data otherwise.

Signed-off-by: David Calavera <[email protected]>
@calavera calavera requested a review from bnusunny September 19, 2022 14:51
Comment on lines +204 to +209
if let Some(value) = headers.get(X_LAMBDA_HTTP_CONTENT_ENCODING) {
if value == "text" {
return convert_to_text(self, content_type);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Once this header is set to 'text', the response will be treated as text response. If a web app returns both text and binary data, it has to set this header based on the type of data returned. This seems to put more work on the web app developers.

Choose a reason for hiding this comment

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

Would it be possible to use the lambda_http::Body to set this behind the scenes?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you can directly use lambda_http::Body to indicate text or binary response. This is for generic http::Body.

@calavera calavera merged commit 6fd5270 into main Oct 5, 2022
@calavera calavera deleted the x_lambda_http_content_encoding branch October 5, 2022 14:55
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