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

It is not possible to get the referer header field #208

Closed
rnowosielski opened this issue Oct 31, 2018 · 12 comments
Closed

It is not possible to get the referer header field #208

rnowosielski opened this issue Oct 31, 2018 · 12 comments
Assignees
Labels
Milestone

Comments

@rnowosielski
Copy link

  • Framework version: 1.2
  • Implementations: Jersey

Scenario

I am trying to retrieve the header from the original request using the @HeaderParam("Referer") annotation e.g

@PUT
@Path("{url}")
@Produces("application/json")
public Response doSomething(@HeaderParam("Referer") String referer) throws Exception {
       logger.info("Referer: " + referer);
}

Expected behavior

The logger should log the value of the referer header that was passed when calling the endpoint

Actual behavior

The log entry states

[main] INFO LambdaHandler - Referer: null

Steps to reproduce

Create an endpoint according to the snippet in the "use case" section, and then call the endpoint by passing Referer header on the request.

@sapessi
Copy link
Collaborator

sapessi commented Oct 31, 2018

Hey @rnowosielski, I just wrote a quick unit test for this. A Referer header is indeed not injected by Jersey, even though I can see it in the event. Funnily enough, when I use the exact same method and @HeaderParam annotation for an X-Custom-Referer header it gets injected correctly. This looks like Jersey's doing. I'm investigating a little bit further.

@sapessi
Copy link
Collaborator

sapessi commented Oct 31, 2018

Never mind, investigated a bit more and it looks like it was indeed a bug. Committing a fix now.

The root cause is that from the JerseyHandlerFilter class I was happily calling the add method of the MultiValuesMap, expecting it to add values to the list and create the list if it didn't exists. It looks like Jersey's implementation does not override this behavior and simply sends to the addNull unimplemented method if the list doesn't already exist. Switched to the addAll method.

@sapessi sapessi self-assigned this Oct 31, 2018
@sapessi sapessi added the bug label Oct 31, 2018
@sapessi sapessi added this to the Release 1.3 milestone Oct 31, 2018
sapessi added a commit that referenced this issue Oct 31, 2018
…Simple add was sending to an unimplemented addNull if the list didn't already exist. Also added unit test for issue #208
@rnowosielski
Copy link
Author

rnowosielski commented Nov 2, 2018

@sapessi Is there a way to download the most recent snapshot version, so I could test it in my code without having to build it myself?

@sapessi
Copy link
Collaborator

sapessi commented Nov 2, 2018

Yes @rnowosielski, changes are committed to the core branch. Just download the code for that branch, mvn install, then add 1.3-SNAPSHOT as a dependency in your code.

@akrambek
Copy link

akrambek commented Nov 12, 2018

@sapessi I am having the same issue and seems to be caused by https://github.com/awslabs/aws-serverless-java-container/blob/master/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequest.java#L808 Any reason why it is replaced with getIdentity().getCaller()?!

@sapessi
Copy link
Collaborator

sapessi commented Nov 12, 2018

Hey @akrambek, that's where API Gateway stores the caller/referer. Could you test with 1.3-SNAPSHOT from the core branch to see if that fixes your issue?

@akrambek
Copy link

hey @sapessi yep it works thanks! Looking forward to the official release.

@rnowosielski
Copy link
Author

@sapessi do you have some rough estimate when 1.3 might go out ?

@sapessi
Copy link
Collaborator

sapessi commented Dec 4, 2018

@rnowosielski my best guess right now is end of December.

@rnowosielski
Copy link
Author

👍 thanks for a quick response.

@sapessi
Copy link
Collaborator

sapessi commented Dec 26, 2018

Resolving in preparation for 1.3 release

@sapessi sapessi closed this as completed Dec 26, 2018
@zsc347
Copy link

zsc347 commented Oct 24, 2019

Hey @akrambek, that's where API Gateway stores the caller/referer. Could you test with 1.3-SNAPSHOT from the core branch to see if that fixes your issue?

Seems API Gateway do not store referer header to getIdentity().getCaller() anymore. But I can get it from multiValueHeaders. Could you check latest behavior?

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

4 participants