Skip to content

Commit

Permalink
Changed ContainerRequest creation to use the method for the headers. …
Browse files Browse the repository at this point in the history
…Simple add was sending to an unimplemented addNull if the list didn't already exist. Also added unit test for issue #208
  • Loading branch information
sapessi committed Oct 31, 2018
1 parent f084177 commit ba7a33c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -167,8 +169,7 @@ private ContainerRequest servletRequestToContainerRequest(ServletRequest request

while (headerNames.hasMoreElements()) {
String headerKey = headerNames.nextElement();
//requestContext.header(headerKey, servletRequest.getHeader(headerKey));
requestContext.getHeaders().add(headerKey, servletRequest.getHeader(headerKey));
requestContext.getHeaders().addAll(headerKey, Collections.list(servletRequest.getHeaders(headerKey)));
}

Timer.stop("JERSEY_SERVLET_REQUEST_TO_CONTAINER");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.amazonaws.serverless.proxy.jersey.model.MapResponseModel;
import com.amazonaws.serverless.proxy.jersey.model.SingleValueModel;

import org.glassfish.jersey.server.ContainerRequest;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -212,4 +214,14 @@ public Response encodedPathParam(@Encoded @PathParam("resource") String resource
sv.setValue(resource);
return Response.ok(sv).build();
}

@Path("/referer-header") @GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response referer(@HeaderParam("Referer") String referer) {
System.out.println("Received referer: " + referer);
SingleValueModel sv = new SingleValueModel();
sv.setValue(referer);
return Response.ok(sv).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,20 @@ public void emptyStream_putNullBody_expectPutToSucceed() {
validateSingleValueModel(resp, CUSTOM_HEADER_KEY);
}

@Test
public void refererHeader_headerParam_expectCorrectInjection() {
String refererValue = "test-referer";
AwsProxyRequest request = new AwsProxyRequestBuilder("/echo/referer-header", "GET")
.nullBody()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.header("Referer", refererValue)
.build();

AwsProxyResponse resp = handler.proxy(request, lambdaContext);
assertEquals(200, resp.getStatusCode());
validateSingleValueModel(resp, refererValue);
}

private void validateMapResponseModel(AwsProxyResponse output) {
validateMapResponseModel(output, CUSTOM_HEADER_KEY, CUSTOM_HEADER_VALUE);
}
Expand Down

0 comments on commit ba7a33c

Please sign in to comment.