Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class LambdaHttpHandler implements RequestHandler<APIGatewayV2HTTPEvent,

private static final Map<String, List<String>> ERROR_HEADERS = Map.of("Content-Type", List.of("application/json"));

private static final String COOKIE_HEADER = "Cookie";

// comma headers for headers that have comma in value and we don't want to split it up into
// multiple headers
private static final Set<String> COMMA_HEADERS = Set.of("access-control-request-headers");
Expand Down Expand Up @@ -198,6 +200,10 @@ httpMethod, ofNullable(request.getRawQueryString())
}
}
}
if (request.getCookies() != null) {
nettyRequest.headers().add(COOKIE_HEADER, String.join("; ", request.getCookies()));
}

if (!nettyRequest.headers().contains(HttpHeaderNames.HOST)) {
nettyRequest.headers().add(HttpHeaderNames.HOST, "localhost");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -42,6 +44,11 @@ public class LambdaHttpHandlerTest {
private static final String QUERY = "testParam1=testValue1&testParam2=testValue2";
private static final String HOST_HEADER = "Host";
private static final String HOST = "localhost";

private static final List<String> COOKIES = List.of("testcookie1=cvalue1", "testcookie2=cvalue2");
private static final String COOKIE_HEADER_KEY = "Cookie";
private static final String COOKIE_HEADER_VALUE = "testcookie1=cvalue1; testcookie2=cvalue2";

private static final String METHOD = "GET";

private final Application application = mock(Application.class);
Expand All @@ -60,6 +67,7 @@ public void mockSetup() {
when(requestContext.getHttp()).thenReturn(requestContextMethod);
when(requestContextMethod.getMethod()).thenReturn(METHOD);
when(request.getHeaders()).thenReturn(Collections.singletonMap(HOST_HEADER, HOST));
when(request.getCookies()).thenReturn(COOKIES);
when(connection.peer()).thenReturn(peer);
when(peer.remoteAddress()).thenReturn(new VirtualAddress("whatever"));
}
Expand Down Expand Up @@ -116,4 +124,13 @@ public void verifyResponseStatusBypass(final HttpResponseStatus status) throws E
assertEquals(status.code(), response.getStatusCode());
}

@Test
public void verifyCookies() throws ExecutionException, InterruptedException {
mockHttpFunction(null, HttpResponseStatus.OK);
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
verify(connection, timeout(PROCESSING_TIMEOUT).times(2)).sendMessage(captor.capture());
DefaultHttpRequest rq = (DefaultHttpRequest) captor.getAllValues().get(0);
assertEquals(COOKIE_HEADER_VALUE, rq.headers().get(COOKIE_HEADER_KEY));
}

}