Skip to content

Commit 1a21b9b

Browse files
author
Mirroring
committed
Merge commit '7128f3eb89703752b89b7852b1b426fbb73cf225'
2 parents d4bf090 + 7128f3e commit 1a21b9b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/StaticAssets/src/StaticAssetsInvoker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private async Task SendRangeAsync(StaticAssetInvocationContext requestContext, R
223223

224224
if (requestContext.Response.StatusCode == StatusCodes.Status200OK)
225225
{
226-
requestContext.Response.StatusCode = StatusCodes.Status416RangeNotSatisfiable;
226+
requestContext.Response.StatusCode = StatusCodes.Status206PartialContent;
227227
}
228228
await ApplyResponseHeadersAsync(requestContext, StatusCodes.Status206PartialContent);
229229

src/StaticAssets/test/StaticAssetsIntegrationTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,33 @@ public async Task IfUnmodifiedSinceDateLessThanLastModifiedShouldReturn412(HttpM
989989
Assert.Equal(HttpStatusCode.PreconditionFailed, res2.StatusCode);
990990
}
991991

992+
// 14.35.2 Range Retrieval Requests
993+
// The presence of a Range header in an unconditional GET modifies
994+
// what is returned if the GET is otherwise successful. In other
995+
// words, the response carries a status code of 206 (Partial
996+
// Content) instead of 200 (OK).
997+
[Fact]
998+
public async Task RangeGivesMatchingRange()
999+
{
1000+
var client = await CreateClient();
1001+
1002+
var req1 = new HttpRequestMessage(HttpMethod.Get, "http://localhost/sample.txt");
1003+
req1.Headers.Range = new RangeHeaderValue(0, 4);
1004+
var res1 = await client.SendAsync(req1);
1005+
1006+
var req2 = new HttpRequestMessage(HttpMethod.Get, "http://localhost/sample.txt");
1007+
req2.Headers.Range = new RangeHeaderValue(7, 11);
1008+
var res2 = await client.SendAsync(req2);
1009+
1010+
Assert.Equal(HttpStatusCode.PartialContent, res1.StatusCode);
1011+
Assert.Equal("Hello", await res1.Content.ReadAsStringAsync());
1012+
Assert.Equal(5, res1.Content.Headers.ContentLength);
1013+
1014+
Assert.Equal(HttpStatusCode.PartialContent, res2.StatusCode);
1015+
Assert.Equal("World", await res2.Content.ReadAsStringAsync());
1016+
Assert.Equal(5, res2.Content.Headers.ContentLength);
1017+
}
1018+
9921019
public static IEnumerable<object[]> SupportedMethods => new[]
9931020
{
9941021
new [] { HttpMethod.Get },

0 commit comments

Comments
 (0)