Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 92b8d56

Browse files
don't send multiple header keys to save space
1 parent 82a05da commit 92b8d56

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/SqlStreamStore.HAL.Tests/OptionsTests.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static IEnumerable<object[]> OptionsAllowedMethodCases()
2727
"/stream",
2828
new[] { HttpMethod.Get, HttpMethod.Head, HttpMethod.Options }
2929
};
30-
30+
3131
yield return new object[]
3232
{
3333
"/stream/123",
@@ -45,7 +45,7 @@ public static IEnumerable<object[]> OptionsAllowedMethodCases()
4545
"/streams/a-stream/0",
4646
new[] { HttpMethod.Get, HttpMethod.Head, HttpMethod.Delete, HttpMethod.Options }
4747
};
48-
48+
4949
yield return new object[]
5050
{
5151
$"/streams/a-stream/{Guid.Empty}",
@@ -73,10 +73,19 @@ public async Task options_returns_the_correct_cors_headers(string requestUri, Ht
7373
{
7474
response.StatusCode.ShouldBe(HttpStatusCode.OK);
7575
response.Headers.GetValues(Constants.Headers.AccessControl.AllowHeaders)
76-
.ShouldBe(new[] { Constants.Headers.ContentType, Constants.Headers.XRequestedWith, Constants.Headers.Authorization }, true);
76+
.SelectMany(x => x.Split(','))
77+
.ShouldBe(new[]
78+
{
79+
Constants.Headers.ContentType,
80+
Constants.Headers.XRequestedWith,
81+
Constants.Headers.Authorization
82+
},
83+
true);
7784
response.Headers.GetValues(Constants.Headers.AccessControl.AllowOrigin)
85+
.SelectMany(x => x.Split(','))
7886
.ShouldBe(new[] { "*" }, true);
7987
response.Headers.GetValues(Constants.Headers.AccessControl.AllowMethods)
88+
.SelectMany(x => x.Split(','))
8089
.ShouldBe(allowedMethods.Select(_ => _.Method), true);
8190
}
8291
}

src/SqlStreamStore.HAL/ApplicationBuilderExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ public static IApplicationBuilder UseAllowedMethods(this IApplicationBuilder bui
4242

4343
Task Options(HttpContext context, Func<Task> next)
4444
{
45-
context.Response.Headers.Append(
45+
context.Response.Headers.AppendCommaSeparatedValues(
4646
Constants.Headers.AccessControl.AllowMethods,
4747
allowedMethodsHeaderValue);
48-
context.Response.Headers.Append(
48+
context.Response.Headers.AppendCommaSeparatedValues(
4949
Constants.Headers.AccessControl.AllowHeaders,
5050
allowedHeadersHeaderValue);
51-
context.Response.Headers.Append(
51+
context.Response.Headers.AppendCommaSeparatedValues(
5252
Constants.Headers.AccessControl.AllowOrigin,
5353
"*");
5454

src/SqlStreamStore.HAL/HttpContextExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private static Task WriteNotModifiedResponse(HttpContext context, Response respo
4949
context.Response.StatusCode = 304;
5050
foreach(var header in s_NotModifiedRequiredHeaders.Where(response.Headers.Keys.Contains))
5151
{
52-
context.Response.Headers.Append(header, response.Headers[header]);
52+
context.Response.Headers.AppendCommaSeparatedValues(header, response.Headers[header]);
5353
}
5454

5555
return Task.CompletedTask;
@@ -61,7 +61,7 @@ private static Task WriteResponseInternal(HttpContext context, Response response
6161

6262
foreach(var header in response.Headers)
6363
{
64-
context.Response.Headers.Append(header.Key, header.Value);
64+
context.Response.Headers.AppendCommaSeparatedValues(header.Key, header.Value);
6565
}
6666

6767
return response.WriteBody(context.Response, context.RequestAborted);

0 commit comments

Comments
 (0)