Skip to content

Commit

Permalink
add cookie value encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
gcbeattyAWS committed Dec 9, 2024
1 parent 396cf47 commit 86b3f5e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static APIGatewayHttpApiV2ProxyRequest ToApiGatewayHttpV2Request(
RouteKey = $"{request.Method} {matchedConfig.Path}",
RawPath = request.Path,
RawQueryString = request.QueryString.Value,
Cookies = request.Cookies.Select(c => $"{c.Key}={c.Value}").ToArray(),
Cookies = request.Cookies.Select(c => $"{c.Key}={HttpUtility.UrlEncode(c.Value)}").ToArray(),
Headers = headers,
QueryStringParameters = queryStringParameters,
PathParameters = pathParameters ?? new Dictionary<string, string>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void ToApiGatewayHttpV2Request_ShouldReturnValidApiGatewayHttpApiV2ProxyR
request.QueryString = new QueryString("?status=pending");
request.Headers["User-Agent"] = "TestAgent";
request.Headers["Accept"] = "application/json";
request.Headers["Cookie"] = "session=abc123; theme=dark";
request.Headers["Cookie"] = "session=abc123; theme=dark; complex=this+has+spaces;";

var result = context.ToApiGatewayHttpV2Request();

Expand All @@ -61,9 +61,10 @@ public void ToApiGatewayHttpV2Request_ShouldReturnValidApiGatewayHttpApiV2ProxyR
Assert.Equal("GET /api/users/{userId}/orders", result.RouteKey);
Assert.Equal("/api/users/123/orders", result.RawPath);
Assert.Equal("?status=pending", result.RawQueryString);
Assert.Equal(2, result.Cookies.Length);
Assert.Equal(3, result.Cookies.Length);
Assert.Contains("session=abc123", result.Cookies);
Assert.Contains("theme=dark", result.Cookies);
Assert.Contains("complex=this%2bhas%2bspaces", result.Cookies);
Assert.Equal("123", result.PathParameters["userId"]);
Assert.Equal("GET", result.RequestContext.Http.Method);
Assert.Equal("/api/users/123/orders", result.RequestContext.Http.Path);
Expand Down

0 comments on commit 86b3f5e

Please sign in to comment.