awslabs / aws-lambda-go-api-proxy

lambda-go-api-proxy makes it easy to port APIs written with Go frameworks such as Gin (https://gin-gonic.github.io/gin/ ) to AWS Lambda and Amazon API Gateway.
Apache License 2.0
1.03k stars 197 forks source link

Why all headers values are split as they are comma separated in EventToRequest? #171

Open arabello opened 1 year ago

arabello commented 1 year ago

I had an issue while integrating a custom header containing a comma , caused by RequestAccessorV2.EventToRequestWithContext: the request returned has the custom header value as an array of two strings (original value split into two parts) instead of an array of a single element (the entire value with the comma).

Looking at the code, it seems that the RequestAccessor splits headers values treating them as they all are comma-separated.

for headerKey, headerValue := range req.Headers {
    for _, val := range strings.Split(headerValue, ",") {
        httpRequest.Header.Add(headerKey, strings.Trim(val, " "))
    }
}

Why so? If an header is not defined as comma-separated no splitting strategy should occur, shouldn't it? What am I missing?

Moreover, why this behavior differs from the RequestAccessor (V1)?