Skip to content

Commit 63c9b2a

Browse files
committed
Revert "updated cookie encoding"
This reverts commit 2ebdb65.
1 parent 2ebdb65 commit 63c9b2a

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/HttpContextExtensions.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,6 @@ public static APIGatewayProxyRequest ToApiGatewayRequest(
8888
var (headers, multiValueHeaders) = _httpRequestUtility.ExtractHeaders(request.Headers);
8989
var (queryStringParameters, multiValueQueryStringParameters) = _httpRequestUtility.ExtractQueryStringParameters(request.Query);
9090

91-
var encodedCookies = request.Cookies.Select(c => $"{c.Key}={HttpUtility.UrlEncode(c.Value)}");
92-
var cookieString = string.Join("; ", encodedCookies);
93-
94-
// Add or update the Cookie header with the URL-encoded cookies
95-
if (!string.IsNullOrEmpty(cookieString))
96-
{
97-
headers["Cookie"] = cookieString;
98-
if (multiValueHeaders.ContainsKey("Cookie"))
99-
{
100-
multiValueHeaders["Cookie"] = [cookieString];
101-
}
102-
else
103-
{
104-
multiValueHeaders.Add("Cookie", [cookieString]);
105-
}
106-
}
107-
10891
var proxyRequest = new APIGatewayProxyRequest
10992
{
11093
Resource = matchedConfig.Path,

Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/HttpContextExtensionsTests.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using Xunit;
66
using Moq;
77
using System.Text;
8-
using Microsoft.Extensions.Primitives;
9-
using System.Linq;
108

119
public class HttpContextExtensionsTests
1210
{
@@ -54,7 +52,7 @@ public void ToApiGatewayHttpV2Request_ShouldReturnValidApiGatewayHttpApiV2ProxyR
5452
request.QueryString = new QueryString("?status=pending");
5553
request.Headers["User-Agent"] = "TestAgent";
5654
request.Headers["Accept"] = "application/json";
57-
request.Headers["Cookie"] = "session=abc123; theme=dark; complex=this+has+special;";
55+
request.Headers["Cookie"] = "session=abc123; theme=dark; complex=this+has+spaces;";
5856

5957
var result = context.ToApiGatewayHttpV2Request();
6058

@@ -66,7 +64,7 @@ public void ToApiGatewayHttpV2Request_ShouldReturnValidApiGatewayHttpApiV2ProxyR
6664
Assert.Equal(3, result.Cookies.Length);
6765
Assert.Contains("session=abc123", result.Cookies);
6866
Assert.Contains("theme=dark", result.Cookies);
69-
Assert.Contains("complex=this%2bhas%2bspecial", result.Cookies);
67+
Assert.Contains("complex=this%2bhas%2bspaces", result.Cookies);
7068
Assert.Equal("123", result.PathParameters["userId"]);
7169
Assert.Equal("GET", result.RequestContext.Http.Method);
7270
Assert.Equal("/api/users/123/orders", result.RequestContext.Http.Path);
@@ -161,37 +159,39 @@ public void ToApiGatewayRequest_ShouldReturnValidApiGatewayProxyRequest()
161159
request.Path = "/api/users/123/orders";
162160
request.QueryString = new QueryString("?status=pending&tag=important&tag=urgent");
163161
request.Headers["User-Agent"] = "TestAgent";
164-
request.Headers["Accept"] = new StringValues(new[] { "text/html", "application/json" });
165-
request.Headers["Cookie"] = "session=abc123; theme=dark; complex=this+has+special;";
162+
request.Headers["Accept"] = new Microsoft.Extensions.Primitives.StringValues(new[] { "text/html", "application/json" });
163+
request.Headers["Cookie"] = "session=abc123; theme=dark";
166164
request.Headers["X-Custom-Header"] = "value1";
167165

168166
_mockHttpRequestUtility.Setup(x => x.ExtractHeaders(It.IsAny<IHeaderDictionary>()))
169167
.Returns((
170168
new Dictionary<string, string>
171169
{
172-
{ "User-Agent", "TestAgent" },
173-
{ "Accept", "application/json" },
174-
{ "X-Custom-Header", "value1" }
170+
{ "User-Agent", "TestAgent" },
171+
{ "Accept", "application/json" },
172+
{ "Cookie", "session=abc123; theme=dark" },
173+
{ "X-Custom-Header", "value1" }
175174
},
176175
new Dictionary<string, IList<string>>
177176
{
178-
{ "User-Agent", new List<string> { "TestAgent" } },
179-
{ "Accept", new List<string> { "text/html", "application/json" } },
180-
{ "X-Custom-Header", new List<string> { "value1" } }
177+
{ "User-Agent", new List<string> { "TestAgent" } },
178+
{ "Accept", new List<string> { "text/html", "application/json" } },
179+
{ "Cookie", new List<string> { "session=abc123; theme=dark" } },
180+
{ "X-Custom-Header", new List<string> { "value1" } }
181181
}
182182
));
183183

184184
_mockHttpRequestUtility.Setup(x => x.ExtractQueryStringParameters(It.IsAny<IQueryCollection>()))
185185
.Returns((
186186
new Dictionary<string, string>
187187
{
188-
{ "status", "pending" },
189-
{ "tag", "urgent" }
188+
{ "status", "pending" },
189+
{ "tag", "urgent" }
190190
},
191191
new Dictionary<string, IList<string>>
192192
{
193-
{ "status", new List<string> { "pending" } },
194-
{ "tag", new List<string> { "important", "urgent" } }
193+
{ "status", new List<string> { "pending" } },
194+
{ "tag", new List<string> { "important", "urgent" } }
195195
}
196196
));
197197

@@ -204,11 +204,13 @@ public void ToApiGatewayRequest_ShouldReturnValidApiGatewayProxyRequest()
204204

205205
Assert.Equal("TestAgent", result.Headers["User-Agent"]);
206206
Assert.Equal("application/json", result.Headers["Accept"]);
207+
Assert.Equal("session=abc123; theme=dark", result.Headers["Cookie"]);
207208
Assert.Equal("value1", result.Headers["X-Custom-Header"]);
208209

209-
var expectedCookieString = $"session={HttpUtility.UrlEncode("abc123")}; theme={HttpUtility.UrlEncode("dark")}; complex={HttpUtility.UrlEncode("this+has+special")}";
210-
Assert.Equal(expectedCookieString, result.Headers["Cookie"]);
211-
Assert.Equal([expectedCookieString], result.MultiValueHeaders["Cookie"]);
210+
Assert.Equal(new List<string> { "TestAgent" }, result.MultiValueHeaders["User-Agent"]);
211+
Assert.Equal(new List<string> { "text/html", "application/json" }, result.MultiValueHeaders["Accept"]);
212+
Assert.Equal(new List<string> { "session=abc123; theme=dark" }, result.MultiValueHeaders["Cookie"]);
213+
Assert.Equal(new List<string> { "value1" }, result.MultiValueHeaders["X-Custom-Header"]);
212214

213215
Assert.Equal("pending", result.QueryStringParameters["status"]);
214216
Assert.Equal("urgent", result.QueryStringParameters["tag"]);

0 commit comments

Comments
 (0)