Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c54cb13

Browse files
committedAug 31, 2023
1 parent db708fe commit c54cb13

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎function-aws-api-proxy-test/src/test/groovy/io/micronaut/function/aws/proxy/test/AwsApiProxyTestServerSpec.groovy

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.micronaut.function.aws.proxy.test
22

3+
import io.micronaut.http.HttpHeaders
34
import io.micronaut.http.HttpRequest
45
import io.micronaut.http.HttpResponse
56
import io.micronaut.http.HttpStatus
@@ -79,6 +80,19 @@ class AwsApiProxyTestServerSpec extends Specification {
7980
response.body.get() == (1..256).collect { it as byte } as byte[]
8081
}
8182

83+
@Issue('https://github.com/micronaut-projects/micronaut-aws/issues/1861')
84+
void 'ensure multiple headers are properly received'() {
85+
when:
86+
HttpResponse<Integer> response = client.toBlocking()
87+
.exchange(HttpRequest.GET('/receive-multiple-headers')
88+
.header(HttpHeaders.ETAG, "A")
89+
.header(HttpHeaders.ETAG, "B"), Integer.class)
90+
91+
then:
92+
response.status == HttpStatus.OK
93+
response.body.get() == 2
94+
}
95+
8296
@Controller
8397
static class TestController {
8498
@Get(value = '/test', produces = MediaType.TEXT_PLAIN)
@@ -105,5 +119,10 @@ class AwsApiProxyTestServerSpec extends Specification {
105119
HttpResponse<byte[]> byteArray() {
106120
return HttpResponse.ok((1..256).collect { it as byte } as byte[])
107121
}
122+
123+
@Get(value = '/receive-multiple-headers', processes = MediaType.TEXT_PLAIN)
124+
Integer receiveMultipleHeaders(HttpRequest<?> request) {
125+
return request.headers.getAll(HttpHeaders.ETAG).size()
126+
}
108127
}
109128
}

‎function-aws-api-proxy/src/main/java/io/micronaut/function/aws/proxy/payload2/APIGatewayV2HTTPEventServletRequest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.micronaut.core.annotation.Internal;
2121
import io.micronaut.core.convert.ConversionService;
2222
import io.micronaut.function.aws.proxy.ApiGatewayServletRequest;
23+
import io.micronaut.http.CaseInsensitiveMutableHttpHeaders;
2324
import io.micronaut.http.MutableHttpHeaders;
2425
import io.micronaut.http.MutableHttpParameters;
2526
import io.micronaut.servlet.http.BodyBuilder;
@@ -29,6 +30,7 @@
2930
import org.slf4j.LoggerFactory;
3031

3132
import java.io.IOException;
33+
import java.util.Arrays;
3234
import java.util.Collections;
3335

3436
/**
@@ -73,7 +75,11 @@ public byte[] getBodyBytes() throws IOException {
7375

7476
@Override
7577
public MutableHttpHeaders getHeaders() {
76-
return getHeaders(requestEvent::getHeaders, Collections::emptyMap);
78+
CaseInsensitiveMutableHttpHeaders headers = new CaseInsensitiveMutableHttpHeaders(conversionService);
79+
requestEvent.getHeaders()
80+
.forEach((key, value) -> Arrays.stream(value.split(","))
81+
.forEach(headerValue -> headers.add(key, headerValue)));
82+
return headers;
7783
}
7884

7985
@Override

0 commit comments

Comments
 (0)
Please sign in to comment.