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

Header user-agent is truncated #464

Closed
bqader opened this issue May 27, 2022 · 5 comments
Closed

Header user-agent is truncated #464

bqader opened this issue May 27, 2022 · 5 comments
Assignees
Labels

Comments

@bqader
Copy link
Contributor

bqader commented May 27, 2022

Serverless Java Container version: Java 11 (Corretto)

Implementations: Jersey (+ Dagger)

Framework version: 2.35

Frontend service: HTTP API

Deployment method: Console

Scenario

We just need to get the client user agent but the value is truncated after the comma.

Expected behavior

servletRequest.getHeader("User-Agent") should return:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36

Actual behavior

servletRequest.getHeader("User-Agent") returns:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML

Steps to reproduce

`
package com.services.test;

import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Enumeration;

@singleton
@path("test")
public class TestService {

private static final Logger logger = LoggerFactory.getLogger(TestService.class);

@Inject
public TestService() {
}

@GET
@Path("user-agent")
@Produces(MediaType.APPLICATION_JSON)
public AwsProxyResponse checkUserAgent(@Context HttpServletRequest servletRequest) {
    final AwsProxyResponse response = new AwsProxyResponse();
    response.setStatusCode(Response.Status.OK.getStatusCode());

    for (Enumeration<?> e = servletRequest.getHeaderNames(); e.hasMoreElements(); ) {
        String nextHeaderName = (String) e.nextElement();
        String headerValue = servletRequest.getHeader(nextHeaderName);
        logger.info("{} = {}", nextHeaderName, headerValue);
    }

    return response;
}

}
`

Full log output

issue_ua

@deki
Copy link
Collaborator

deki commented May 30, 2022

Thanks for your bug report. Currently I'm not aware of any place where we modify this header inside the framework (it's taken from the $context.identity API Gateway object).
Will reproduce and investigate.

@bqader
Copy link
Contributor Author

bqader commented May 30, 2022

Is it not in AwsHttpApiV2ProxyHttpServletRequest.headersMapToMultiValue ?

@deki
Copy link
Collaborator

deki commented May 30, 2022

Good catch, that looks suspicious. Would you be willing to submit a pull request along with a small unittest?

@bqader
Copy link
Contributor Author

bqader commented May 30, 2022

Ok I'll do my best to do it this week.

bqader added a commit to bqader/aws-serverless-java-container that referenced this issue May 30, 2022
@deki deki added the bug label May 31, 2022
@deki deki self-assigned this Jun 10, 2022
@deki
Copy link
Collaborator

deki commented Jun 10, 2022

Fix is part of release 1.8.2

@deki deki closed this as completed Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants