Skip to content

Commit 5177698

Browse files
authored
Merge pull request #25851 from jazva/cookie-http
2 parents 3f4562f + 703b80f commit 5177698

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class LambdaHttpHandler implements RequestHandler<APIGatewayV2HTTPEvent,
5252

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

55+
private static final String COOKIE_HEADER = "Cookie";
56+
5557
// comma headers for headers that have comma in value and we don't want to split it up into
5658
// multiple headers
5759
private static final Set<String> COMMA_HEADERS = Set.of("access-control-request-headers");
@@ -198,6 +200,10 @@ httpMethod, ofNullable(request.getRawQueryString())
198200
}
199201
}
200202
}
203+
if (request.getCookies() != null) {
204+
nettyRequest.headers().add(COOKIE_HEADER, String.join("; ", request.getCookies()));
205+
}
206+
201207
if (!nettyRequest.headers().contains(HttpHeaderNames.HOST)) {
202208
nettyRequest.headers().add(HttpHeaderNames.HOST, "localhost");
203209
}

extensions/amazon-lambda-http/runtime/src/test/java/io/quarkus/amazon/lambda/http/LambdaHttpHandlerTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
import java.util.Arrays;
1111
import java.util.Collections;
12+
import java.util.List;
1213
import java.util.concurrent.CompletableFuture;
1314
import java.util.concurrent.ExecutionException;
1415
import java.util.concurrent.TimeUnit;
1516

1617
import org.junit.jupiter.api.BeforeEach;
18+
import org.junit.jupiter.api.Test;
1719
import org.junit.jupiter.params.ParameterizedTest;
1820
import org.junit.jupiter.params.provider.MethodSource;
1921
import org.mockito.ArgumentCaptor;
@@ -42,6 +44,11 @@ public class LambdaHttpHandlerTest {
4244
private static final String QUERY = "testParam1=testValue1&testParam2=testValue2";
4345
private static final String HOST_HEADER = "Host";
4446
private static final String HOST = "localhost";
47+
48+
private static final List<String> COOKIES = List.of("testcookie1=cvalue1", "testcookie2=cvalue2");
49+
private static final String COOKIE_HEADER_KEY = "Cookie";
50+
private static final String COOKIE_HEADER_VALUE = "testcookie1=cvalue1; testcookie2=cvalue2";
51+
4552
private static final String METHOD = "GET";
4653

4754
private final Application application = mock(Application.class);
@@ -60,6 +67,7 @@ public void mockSetup() {
6067
when(requestContext.getHttp()).thenReturn(requestContextMethod);
6168
when(requestContextMethod.getMethod()).thenReturn(METHOD);
6269
when(request.getHeaders()).thenReturn(Collections.singletonMap(HOST_HEADER, HOST));
70+
when(request.getCookies()).thenReturn(COOKIES);
6371
when(connection.peer()).thenReturn(peer);
6472
when(peer.remoteAddress()).thenReturn(new VirtualAddress("whatever"));
6573
}
@@ -116,4 +124,13 @@ public void verifyResponseStatusBypass(final HttpResponseStatus status) throws E
116124
assertEquals(status.code(), response.getStatusCode());
117125
}
118126

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

0 commit comments

Comments
 (0)