Skip to content
This repository was archived by the owner on Oct 8, 2023. It is now read-only.

Commit 042b9c7

Browse files
committed
Allow specifying header for binary repsonse
1 parent 65ef905 commit 042b9c7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/main/java/com/github/kaklakariada/aws/lambda/model/response/ApiGatewayResponse.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
*/
1818
package com.github.kaklakariada.aws.lambda.model.response;
1919

20+
import static java.util.Collections.emptyMap;
21+
2022
import java.util.Base64;
21-
import java.util.Collections;
2223
import java.util.Map;
2324

2425
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -33,19 +34,31 @@ public ApiGatewayResponse(int statusCode, Map<String, String> headers, String bo
3334
this(statusCode, headers, body, false);
3435
}
3536

37+
public ApiGatewayResponse(int statusCode, Map<String, String> headers, byte[] body) {
38+
this(statusCode, headers, base64Encode(body), true);
39+
}
40+
3641
private ApiGatewayResponse(int statusCode, Map<String, String> headers, String body, boolean base64Encoded) {
3742
this.statusCode = statusCode;
3843
this.headers = headers;
3944
this.body = body;
4045
this.base64Encoded = base64Encoded;
4146
}
4247

48+
public static ApiGatewayResponse ok(Map<String, String> headers, String body) {
49+
return new ApiGatewayResponse(200, headers, body);
50+
}
51+
4352
public static ApiGatewayResponse ok(String body) {
44-
return new ApiGatewayResponse(200, Collections.emptyMap(), body);
53+
return ok(emptyMap(), body);
54+
}
55+
56+
public static ApiGatewayResponse ok(Map<String, String> headers, byte[] body) {
57+
return new ApiGatewayResponse(200, headers, base64Encode(body), true);
4558
}
4659

4760
public static ApiGatewayResponse ok(byte[] body) {
48-
return new ApiGatewayResponse(200, Collections.emptyMap(), base64Encode(body), true);
61+
return ok(emptyMap(), body);
4962
}
5063

5164
private static String base64Encode(byte[] body) {

0 commit comments

Comments
 (0)