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

[Bug] API Gateway Payload V2: Multiple Headers with same name come as one #1861

Closed
driverpt opened this issue Aug 31, 2023 · 3 comments · May be fixed by #1862
Closed

[Bug] API Gateway Payload V2: Multiple Headers with same name come as one #1861

driverpt opened this issue Aug 31, 2023 · 3 comments · May be fixed by #1862
Assignees
Labels
type: bug Something isn't working

Comments

@driverpt
Copy link
Contributor

Expected Behavior

HttpRequest<?> to return proper Headers

Actual Behaviour

Returns same Header with values separated by Commas

Steps To Reproduce

    @Issue('https://github.com/micronaut-projects/micronaut-aws/issues/1858')
    void 'ensure multiple headers are properly received'() {
        when:
        HttpResponse<Integer> response = client.toBlocking()
                .exchange(HttpRequest.GET('/receive-multiple-headers')
                            .header(HttpHeaders.ETAG, "A")
                            .header(HttpHeaders.ETAG, "B"), Integer.class)

        then:
        response.status == HttpStatus.OK
        response.body.get() == 2
    }
        @Get(value = '/receive-multiple-headers', processes = MediaType.TEXT_PLAIN)
        Integer receiveMultipleHeaders(HttpRequest<?> request) {
            return request.headers.getAll(HttpHeaders.ETAG).size()
        }

Environment Information

  • Operating System: MacOS
  • JVM: 17

Example Application

No response

Version

Latest with AWS 4.0.3

driverpt added a commit to driverpt/micronaut-aws that referenced this issue Aug 31, 2023
driverpt added a commit to driverpt/micronaut-aws that referenced this issue Aug 31, 2023
@sdelamo
Copy link
Contributor

sdelamo commented Aug 31, 2023

we need to add a test to the core server TCK. Similar to micronaut-projects/micronaut-core#9791

@driverpt Do you want to contribute that PR to core?

@sdelamo sdelamo added the type: bug Something isn't working label Aug 31, 2023
@sdelamo sdelamo removed this from 4.2.0 Release Aug 31, 2023
@driverpt
Copy link
Contributor Author

driverpt commented Aug 31, 2023

Hello,

After some digging and Testing with AWS API Gateway Payload V2, I have discovered that If a header value contains a comma, it's appended "as is".

i.e.:

X-SomeHeader: Foo,Bar
X-SomeHeader: Baz

We will have something like:
image

A comma is widely used in most User-Agent Strings. Example: Safari: Mozilla/5.0 (Macintosh; Intel Mac OS X 13_5_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15, which was causing the PR I've created to break TCK Tests.

What is possibly needed is a Property that would tell the Request Converter not to split by comma in certain headers.

WDYT @sdelamo @graemerocher @timyates ?

@msailes , can you also provide some insights on this?

@sdelamo
Copy link
Contributor

sdelamo commented Nov 24, 2023

I just check this with Micronaut Framework 4.2.0

Sending a request such as:

GET /headers HTTP/1.1
ETag: A
ETag: B
Host: pr76sk5f71.execute-api.us-east-1.amazonaws.com
Connection: close
User-Agent: RapidAPI/4.2.0 (Macintosh; OS X/13.6.1) GCDHTTPRequest

with a controller:

package temp1;

import io.micronaut.http.HttpHeaders;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Controller("/headers")
public class HeadersController {

    @Get
    Map<String, List<String>> receiveMultipleHeaders(HttpRequest<?> request) {
        return Collections.singletonMap("etag" , request.getHeaders().getAll(HttpHeaders.ETAG));
    }
}

we get response:

HTTP/1.1 200 OK
Date: Fri, 24 Nov 2023 12:17:38 GMT
Content-Type: application/json
Content-Length: 16
Connection: close
Apigw-Requestid: O5wfYhZroAMEJlg=

{"etag":["A,B"]}

I am going to close this issue for now. @driverpt let me know if you think we should do any changes about this.

@sdelamo sdelamo closed this as completed Nov 24, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in 4.1.7 Release Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
No open projects
Status: Done
2 participants