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

Add custom response header to force text encoding #533

Merged
merged 1 commit into from Oct 5, 2022

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 david.calavera@gmail.com

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 <david.calavera@gmail.com>
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.

None yet

3 participants