Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [Bug] API GW V2 Payload setting same header on Single and MultiValue #1858 #1859

Closed
wants to merge 1 commit into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ private void populateHeaders(@NonNull ConversionService conversionService,
MutableMapListOfStringAndMapStringConvertibleMultiValue entries = new MutableMapListOfStringAndMapStringConvertibleMultiValue(conversionService, multiValueHeaders, singleHeaders);

for (String name: entries.names()) {
response.addHeader(name, String.join(",", entries.getAll(name)));
entries.getAll(name)
.forEach(headerValue -> response.addHeader(name, headerValue));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.micronaut.function.aws.proxy.test

import io.micronaut.http.HttpHeaders
import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.HttpStatus
Expand Down Expand Up @@ -79,6 +80,19 @@ class AwsApiProxyTestServerSpec extends Specification {
response.body.get() == (1..256).collect { it as byte } as byte[]
}

@Issue('https://github.com/micronaut-projects/micronaut-aws/issues/1858')
void 'can return a ByteArray'() {
when:
HttpResponse<?> response = client.toBlocking()
.exchange(HttpRequest.GET('/multiple-headers'))

then:
response.status == HttpStatus.OK
response.headers.getAll(HttpHeaders.LINK) ==
['<https://example1.com>; rel="next"', '<https://example2.com>; rel="prev"']
response.headers.get(HttpHeaders.CACHE_CONTROL) == "no-cache"
}

@Controller
static class TestController {
@Get(value = '/test', produces = MediaType.TEXT_PLAIN)
Expand All @@ -105,5 +119,13 @@ class AwsApiProxyTestServerSpec extends Specification {
HttpResponse<byte[]> byteArray() {
return HttpResponse.ok((1..256).collect { it as byte } as byte[])
}

@Get(value = '/multiple-headers', processes = MediaType.TEXT_PLAIN)
HttpResponse emptyBody() {
return HttpResponse.ok()
.header(HttpHeaders.LINK, '<https://example1.com>; rel="next"')
.header(HttpHeaders.LINK, '<https://example2.com>; rel="prev"')
.header(HttpHeaders.CACHE_CONTROL, "no-cache")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ private MapCollapseUtils() {
public static Map<String, String> getSingleValueHeaders(MutableHttpHeaders headers) {
Map<String, String> result = new HashMap<>();
for (String paramName : headers.names()) {
result.put(paramName, headers.get(paramName));
List<String> values = headers.getAll(paramName);
if (values.size() == 1) {
result.put(paramName, values.get(0));
}
}
return result;
}
Expand All @@ -57,7 +60,10 @@ public static Map<String, String> getSingleValueHeaders(MutableHttpHeaders heade
public static Map<String, List<String>> getMultiHeaders(MutableHttpHeaders headers) {
Map<String, List<String>> result = new HashMap<>();
for (String paramName : headers.names()) {
result.put(paramName, headers.getAll(paramName));
List<String> values = headers.getAll(paramName);
if (values.size() > 1) {
result.put(paramName, values);
}
}
return result;
}
Expand Down