From 6e7b29e61977f2c199a4aaf3014dfbfebdba9701 Mon Sep 17 00:00:00 2001 From: Richard Thomas Date: Tue, 23 Mar 2021 23:34:13 +0100 Subject: [PATCH 1/2] Set Content-Type on APIGatewayV2HTTPResponse --- .../amazon/lambda/http/LambdaHttpHandler.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java b/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java index fa99269e88ee1f..f7db1aec264f58 100644 --- a/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java +++ b/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java @@ -6,6 +6,7 @@ import java.nio.channels.WritableByteChannel; import java.nio.charset.StandardCharsets; import java.util.Base64; +import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -25,6 +26,7 @@ import io.netty.handler.codec.http.DefaultLastHttpContent; import io.netty.handler.codec.http.HttpContent; import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpVersion; @@ -92,6 +94,16 @@ public void handleMessage(Object msg) { HttpResponse res = (HttpResponse) msg; responseBuilder.setStatusCode(res.status().code()); + final HttpHeaders responseHeaders = res.headers(); + if (responseHeaders != null) { + final String contentType = responseHeaders.getAsString("Content-Type"); + if (contentType != null && contentType.trim().length() > 0) { + final Map headers = new HashMap<>(); + headers.put("Content-Type", contentType); + responseBuilder.setHeaders(headers); + } + } + Headers multiValueHeaders = new Headers(); responseBuilder.setMultiValueHeaders(multiValueHeaders); for (String name : res.headers().names()) { From 398ec32e40c9bf0c8a21943400a6c3018cc56ca2 Mon Sep 17 00:00:00 2001 From: Richard Thomas Date: Wed, 24 Mar 2021 21:19:48 +0100 Subject: [PATCH 2/2] Use HttpHeaderNames constant --- .../java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java b/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java index f7db1aec264f58..93b1ef4d9c5e7a 100644 --- a/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java +++ b/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java @@ -96,7 +96,7 @@ public void handleMessage(Object msg) { final HttpHeaders responseHeaders = res.headers(); if (responseHeaders != null) { - final String contentType = responseHeaders.getAsString("Content-Type"); + final String contentType = responseHeaders.getAsString(HttpHeaderNames.CONTENT_TYPE); if (contentType != null && contentType.trim().length() > 0) { final Map headers = new HashMap<>(); headers.put("Content-Type", contentType);