Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions archetypes/jersey/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<groupId>com.amazonaws.serverless.archetypes</groupId>
Expand Down
1 change: 1 addition & 0 deletions archetypes/spark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<groupId>com.amazonaws.serverless.archetypes</groupId>
Expand Down
1 change: 1 addition & 0 deletions archetypes/spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<groupId>com.amazonaws.serverless.archetypes</groupId>
Expand Down
1 change: 1 addition & 0 deletions archetypes/springboot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<groupId>com.amazonaws.serverless.archetypes</groupId>
Expand Down
1 change: 1 addition & 0 deletions aws-serverless-java-container-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,17 @@ public Collection<String> getHeaderNames() {

@Override
public String getCharacterEncoding() {
return headers.getFirst(HttpHeaders.CONTENT_ENCODING);
final String contentType = Optional.ofNullable(getContentType()).orElse("");
if (contentType.contains(";")) {
return contentType.split(";")[1].split("=")[1].trim().toLowerCase(Locale.getDefault());
} else {
return "";
}
}


@Override
public String getContentType() {
return headers.getFirst(HttpHeaders.CONTENT_TYPE);
}
public String getContentType() { return getHeader(HttpHeaders.CONTENT_TYPE); }


@Override
Expand Down Expand Up @@ -334,7 +337,10 @@ public PrintWriter getWriter() throws IOException {

@Override
public void setCharacterEncoding(String s) {
setHeader(HttpHeaders.CONTENT_ENCODING, s, true);
final String characterEncoding = Optional.ofNullable(s).orElse("").toLowerCase(Locale.getDefault());
final String oldValue = Optional.ofNullable(getHeader(HttpHeaders.CONTENT_TYPE)).orElse("");
String contentType = oldValue.contains(";") ? oldValue.split(";")[0].trim(): oldValue;
setHeader(HttpHeaders.CONTENT_TYPE, String.format("%s; charset=%s", contentType, characterEncoding), true);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,49 @@ public void cookie_addCookieWithoutMaxAge_expectNoExpires() {
assertFalse(cookieHeader.contains("Expires"));
}

@Test
public void characterEncoding_setCharacterEncoding() {
AwsHttpServletResponse resp = new AwsHttpServletResponse(null, null);
resp.setContentType("application/json");
resp.setCharacterEncoding("UTF-8");
assertNotEquals("UTF-8", resp.getHeader("Content-Encoding"));
assertEquals("application/json; charset=utf-8", resp.getContentType());
assertEquals("application/json; charset=utf-8", resp.getHeader("Content-Type"));
}

@Test
public void characterEncoding_setContentType() {
AwsHttpServletResponse resp = new AwsHttpServletResponse(null, null);
resp.setContentType("application/json; charset=utf-8");
resp.setCharacterEncoding("UTF-8");

assertEquals("application/json; charset=utf-8", resp.getContentType());
assertEquals("application/json; charset=utf-8", resp.getHeader("Content-Type"));
assertEquals("utf-8", resp.getCharacterEncoding());
}

@Test
public void characterEncoding_setContentTypeAndsetCharacterEncoding() {
AwsHttpServletResponse resp = new AwsHttpServletResponse(null, null);
resp.setContentType("application/json");
resp.setCharacterEncoding("UTF-8");

assertEquals("application/json; charset=utf-8", resp.getContentType());
assertEquals("application/json; charset=utf-8", resp.getHeader("Content-Type"));
assertEquals("utf-8", resp.getCharacterEncoding());
}

@Test
public void characterEncoding_setCharacterEncodingAndsetContentType() {
AwsHttpServletResponse resp = new AwsHttpServletResponse(null, null);
resp.setCharacterEncoding("UTF-8");
resp.setContentType("application/json");

assertEquals("application/json", resp.getContentType());
assertEquals("application/json", resp.getHeader("Content-Type"));
assertEquals("", resp.getCharacterEncoding());
}

private int getMaxAge(String header) {
Matcher ageMatcher = MAX_AGE_PATTERN.matcher(header);
assertTrue(ageMatcher.find());
Expand Down
1 change: 1 addition & 0 deletions aws-serverless-java-container-jersey/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<properties>
Expand Down
1 change: 1 addition & 0 deletions aws-serverless-java-container-spark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<properties>
Expand Down
1 change: 1 addition & 0 deletions aws-serverless-java-container-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<properties>
Expand Down