Skip to content

Commit

Permalink
Copy value of Content-Type from Netty response headers to AWS respons…
Browse files Browse the repository at this point in the history
…e builder
  • Loading branch information
richiethom committed Mar 26, 2021
1 parent 2fbb0a6 commit 5ebe4d3
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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(HttpHeaderNames.CONTENT_TYPE);
if (contentType != null && contentType.trim().length() > 0) {
final Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", contentType);
responseBuilder.setHeaders(headers);
}
}

Headers multiValueHeaders = new Headers();
responseBuilder.setMultiValueHeaders(multiValueHeaders);
for (String name : res.headers().names()) {
Expand Down

0 comments on commit 5ebe4d3

Please sign in to comment.