fix(lambda): add cookies array to function URL events (#5288)

* Fix #5255

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-10-07 22:35:51 -04:00
1 parent 985921c3db
commit 673c809eff
5 files changed
+127 -20

No files matched your search

@@ -0,0 +1,41 @@
package io.github.hectorvent.floci.core.common;
import jakarta.ws.rs.core.HttpHeaders;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Reads the {@code cookies} array of a payload format 2.0 Lambda event, which HTTP API
* integrations, HTTP API Lambda authorizers and function URLs all send, from the request's
* {@code Cookie} headers.
*/
public final class CookieHeaders {
private CookieHeaders() {
}
/**
* Every cookie-pair from every {@code Cookie} header, in request order. The header name
* matches case-insensitively, each value is split on {@code ;}, pairs are trimmed and empty
* segments are dropped.
*/
public static List<String> cookiePairs(Map<String, List<String>> requestHeaders) {
List<String> cookies = new ArrayList<>();
for (Map.Entry<String, List<String>> e : requestHeaders.entrySet()) {
if (!HttpHeaders.COOKIE.equalsIgnoreCase(e.getKey())) {
continue;
}
for (String header : e.getValue()) {
for (String cookie : header.split(";")) {
String trimmed = cookie.trim();
if (!trimmed.isEmpty()) {
cookies.add(trimmed);
}
}
}
}
return cookies;
}
}
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.CookieHeaders;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.core.common.auth.SigV4AuthorizationHeader;
@@ -3551,7 +3552,7 @@ public class ApiGatewayExecuteController {
private static void putV2CookiesHeadersAndQuery(ObjectNode event,
MultivaluedMap<String, String> requestHeaders,
MultivaluedMap<String, String> queryParams) {
List<String> cookies = v2Cookies(requestHeaders);
List<String> cookies = CookieHeaders.cookiePairs(requestHeaders);
if (!cookies.isEmpty()) {
ArrayNode cookiesNode = event.putArray("cookies");
cookies.forEach(cookiesNode::add);
@@ -3574,25 +3575,6 @@ public class ApiGatewayExecuteController {
}
}
/** Every cookie-pair from every {@code Cookie} header, in request order. */
private static List<String> v2Cookies(MultivaluedMap<String, String> requestHeaders) {
List<String> cookies = new ArrayList<>();
for (Map.Entry<String, List<String>> e : requestHeaders.entrySet()) {
if (!HttpHeaders.COOKIE.equalsIgnoreCase(e.getKey())) {
continue;
}
for (String header : e.getValue()) {
for (String cookie : header.split(";")) {
String trimmed = cookie.trim();
if (!trimmed.isEmpty()) {
cookies.add(trimmed);
}
}
}
}
return cookies;
}
private static boolean isV2TextContentType(String contentType) {
if (contentType == null || contentType.isBlank()) {
return false;
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.lambda;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.CookieHeaders;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
@@ -10,6 +11,7 @@ import io.github.hectorvent.floci.services.lambda.model.LambdaAlias;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
@@ -33,6 +35,7 @@ import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Base64;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
@@ -147,6 +150,12 @@ public class LambdaUrlInvocationController {
root.put("rawPath", rawPath);
root.put("rawQueryString", uriInfo.getRequestUri().getRawQuery() != null ? uriInfo.getRequestUri().getRawQuery() : "");
List<String> cookies = CookieHeaders.cookiePairs(headers.getRequestHeaders());
if (!cookies.isEmpty()) {
ArrayNode cookiesNode = root.putArray("cookies");
cookies.forEach(cookiesNode::add);
}
ObjectNode headersNode = root.putObject("headers");
headers.getRequestHeaders().forEach((k, v) -> headersNode.put(k.toLowerCase(), String.join(",", v)));