-
Notifications
You must be signed in to change notification settings - Fork 560
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
"Content-Type: application/json" does not uses UTF-8 charset by default #352
Comments
Have just ran into the exact same issue (with character conversion happening in the handler despite UTF-8 being supplied in). @yeDor - just to confirm - the workaround you've outlined above works perfectly, but would be great to see this resolved in the library itself. |
sapessi
added a commit
that referenced
this issue
Jul 10, 2020
sapessi
added a commit
that referenced
this issue
Jul 10, 2020
sapessi
added a commit
that referenced
this issue
Jul 10, 2020
sapessi
added a commit
that referenced
this issue
Jul 15, 2020
* fix: Adding pathParameters to v2 proxy event as reported in #358. * fix: Address JSON content type issue reported in #352 and #344 * fix: Fixed bug caught by integration tests for #352 * fix: Fix struts tests for the changes made for #352 * test: Attempting to replicate the issue reported in #342 * test: Reverting exception test in Spring package since it's only available in Spring5, not Spring4 * fix: Sigh, forgot to remove the import for the class that doesn't exist from the previous commit * fix: Addresses bug reported in query string parsing (#363) for HTTP API support where we have a query string key, followed by a value declarator (=), but then no value * chore: Update GitHub issue and PR templates * fix: Fixed issue reported by SpotBugs with the exception logging of the HTTP API query string parsing
Release |
jogep
pushed a commit
to jogep/aws-serverless-java-container
that referenced
this issue
Dec 8, 2020
* fix: Adding pathParameters to v2 proxy event as reported in aws#358. * fix: Address JSON content type issue reported in aws#352 and aws#344 * fix: Fixed bug caught by integration tests for aws#352 * fix: Fix struts tests for the changes made for aws#352 * test: Attempting to replicate the issue reported in aws#342 * test: Reverting exception test in Spring package since it's only available in Spring5, not Spring4 * fix: Sigh, forgot to remove the import for the class that doesn't exist from the previous commit * fix: Addresses bug reported in query string parsing (aws#363) for HTTP API support where we have a query string key, followed by a value declarator (=), but then no value * chore: Update GitHub issue and PR templates * fix: Fixed issue reported by SpotBugs with the exception logging of the HTTP API query string parsing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scenario
A Lambda with responses of type json: "Content-Type: application/json"
The lambda is behind an API Gateway. /{proxy+}
Do a GET on the resource and get the object as JSON in UTF-8 charset according to https://tools.ietf.org/html/rfc4627#section-3
Example controller:
Expected behavior
Getting the objects with their content in UTF-8 regardless if "charset=UTF-8" specified or not, according to https://tools.ietf.org/html/rfc4627#section-3.
Actual behavior
Test with "Content-Type":"application/json" fails with
Test with "Content-Type":["application/json; charset=UTF-8"] works as expected:
Spring MVC Test without "aws-serverless-java-container" works as expected:
Full log output
[2020-05-25 10:09:49,093] INFO [main] d.p.p.s.SenderStreamLambdaHandler - Output: {"statusCode":200,"multiValueHeaders":{"Cache-Control":["no-cache, no-store, max-age=0, must-revalidate"],"Content-Type":["application/json"],"Expires":["0"],"Pragma":["no-cache"],"Vary":["Origin","Access-Control-Request-Method","Access-Control-Request-Headers","Origin","Access-Control-Request-Method","Access-Control-Request-Headers"],"X-Content-Type-Options":["nosniff"],"X-Frame-Options":["DENY"],"X-XSS-Protection":["1; mode=block"]},"body":"{"s":"öüä� ������"}","isBase64Encoded":false}
Issue
com.amazonaws.serverless.proxy.model.ContainerConfig#getDefaultContentCharset is ISO-8859-1 regardless from MIME-type.
-> com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletResponse#flushBuffer
responseBody = new String(bodyOutputStream.toByteArray(), charset);
bodyOutputStream is in UTF-8 but responseBody is constructed with ISO-8859-1
Notes
MediaType.APPLICATION_JSON_UTF8_VALUE is Deprecated
as of 5.2 in favor of APPLICATION_JSON_VALUE since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring a charset=UTF-8 parameter
Possible workaround
Change the default charset in the constructor method of your Lambda handler class:
LambdaContainerHandler.getContainerConfig().setDefaultContentCharset("UTF-8");
The text was updated successfully, but these errors were encountered: