Skip to content

Commit afd6916

Browse files
Add some default binary types and minor tweaks
1 parent 58c2c3c commit afd6916

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletResponseWriter.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ public AwsProxyResponse writeResponse(AwsHttpServletResponse containerResponse,
5858
}
5959

6060
private boolean isBinary(String contentType) {
61-
return contentType == null ? false : LambdaContainerHandler.getContainerConfig().isBinaryContentType(contentType);
61+
if(contentType != null) {
62+
int semidx = contentType.indexOf(';');
63+
if(semidx >= 0) {
64+
return LambdaContainerHandler.getContainerConfig().isBinaryContentType(contentType.substring(0, semidx));
65+
}
66+
else {
67+
LambdaContainerHandler.getContainerConfig().isBinaryContentType(contentType);
68+
}
69+
}
70+
return false;
6271
}
6372
}

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/model/ContainerConfig.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static ContainerConfig defaultConfig() {
2323
configuration.setUseStageAsServletContext(false);
2424
configuration.setValidFilePaths(DEFAULT_FILE_PATHS);
2525
configuration.setQueryStringCaseSensitive(false);
26+
configuration.addBinaryContentTypes("application/octet-stream", "image/jpeg", "image/png", "image/gif");
2627

2728
return configuration;
2829
}
@@ -223,20 +224,23 @@ public void setQueryStringCaseSensitive(boolean queryStringCaseSensitive) {
223224
}
224225

225226
/**
226-
* Configure specified content type as binary
227+
* Configure specified content type(s) as binary
228+
* @param contentTypes list of exact content types that will be considered as binary
227229
*/
228-
public void addBinaryContentType(String type) {
229-
if(type != null) {
230-
binaryContentTypes.add(type);
230+
public void addBinaryContentTypes(String... contentTypes) {
231+
if(contentTypes != null) {
232+
for(String type: contentTypes) {
233+
binaryContentTypes.add(type);
234+
}
231235
}
232236
}
233237

234238
/**
235239
* Determine if specified content type has been configured as binary
236-
* @param type
240+
* @param contentType content type to query
237241
* @return
238242
*/
239-
public boolean isBinaryContentType(String type) {
240-
return binaryContentTypes.contains(type);
243+
public boolean isBinaryContentType(String contentType) {
244+
return contentType != null && binaryContentTypes.contains(contentType.trim());
241245
}
242246
}

0 commit comments

Comments
 (0)