Skip to content

Commit

Permalink
Merge commit '7128f3eb89703752b89b7852b1b426fbb73cf225'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirroring committed Jan 14, 2025
2 parents d4bf090 + 7128f3e commit 1a21b9b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/StaticAssets/src/StaticAssetsInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private async Task SendRangeAsync(StaticAssetInvocationContext requestContext, R

if (requestContext.Response.StatusCode == StatusCodes.Status200OK)
{
requestContext.Response.StatusCode = StatusCodes.Status416RangeNotSatisfiable;
requestContext.Response.StatusCode = StatusCodes.Status206PartialContent;
}
await ApplyResponseHeadersAsync(requestContext, StatusCodes.Status206PartialContent);

Expand Down
27 changes: 27 additions & 0 deletions src/StaticAssets/test/StaticAssetsIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,33 @@ public async Task IfUnmodifiedSinceDateLessThanLastModifiedShouldReturn412(HttpM
Assert.Equal(HttpStatusCode.PreconditionFailed, res2.StatusCode);
}

// 14.35.2 Range Retrieval Requests
// The presence of a Range header in an unconditional GET modifies
// what is returned if the GET is otherwise successful. In other
// words, the response carries a status code of 206 (Partial
// Content) instead of 200 (OK).
[Fact]
public async Task RangeGivesMatchingRange()
{
var client = await CreateClient();

var req1 = new HttpRequestMessage(HttpMethod.Get, "http://localhost/sample.txt");
req1.Headers.Range = new RangeHeaderValue(0, 4);
var res1 = await client.SendAsync(req1);

var req2 = new HttpRequestMessage(HttpMethod.Get, "http://localhost/sample.txt");
req2.Headers.Range = new RangeHeaderValue(7, 11);
var res2 = await client.SendAsync(req2);

Assert.Equal(HttpStatusCode.PartialContent, res1.StatusCode);
Assert.Equal("Hello", await res1.Content.ReadAsStringAsync());
Assert.Equal(5, res1.Content.Headers.ContentLength);

Assert.Equal(HttpStatusCode.PartialContent, res2.StatusCode);
Assert.Equal("World", await res2.Content.ReadAsStringAsync());
Assert.Equal(5, res2.Content.Headers.ContentLength);
}

public static IEnumerable<object[]> SupportedMethods => new[]
{
new [] { HttpMethod.Get },
Expand Down

0 comments on commit 1a21b9b

Please # to comment.