Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Port fix for #6875: Only set Content-Length when serving body (#6888)
Browse files Browse the repository at this point in the history
Addresses #6887
  • Loading branch information
jbagga committed Sep 25, 2017
1 parent 1ca5884 commit bd8b4d8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ internal enum PreconditionState
// Assuming the request is not a range request, the Content-Length header is set to the length of the entire file.
// If the request is a valid range request, this header is overwritten with the length of the range as part of the
// range processing (see method SetContentLength).
response.ContentLength = fileLength.Value;

if (serveBody)
{
response.ContentLength = fileLength.Value;
}

if (enableRangeProcessing)
{
SetAcceptRangeHeader(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public async Task WriteFileAsync_PreconditionFailed()
var streamReader = new StreamReader(httpResponse.Body);
var body = streamReader.ReadToEndAsync().Result;
Assert.Equal(StatusCodes.Status412PreconditionFailed, httpResponse.StatusCode);
Assert.Equal(11, httpResponse.ContentLength);
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Empty(body);
Expand Down Expand Up @@ -417,7 +417,7 @@ public async Task WriteFileAsync_NotModified()
var streamReader = new StreamReader(httpResponse.Body);
var body = streamReader.ReadToEndAsync().Result;
Assert.Equal(StatusCodes.Status304NotModified, httpResponse.StatusCode);
Assert.Equal(11, httpResponse.ContentLength);
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Empty(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public async Task WriteFileAsync_RangeRequested_PreconditionFailed()
var streamReader = new StreamReader(httpResponse.Body);
var body = streamReader.ReadToEndAsync().Result;
Assert.Equal(StatusCodes.Status412PreconditionFailed, httpResponse.StatusCode);
Assert.Equal(11, httpResponse.ContentLength);
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Empty(body);
Expand Down Expand Up @@ -408,7 +408,7 @@ public async Task WriteFileAsync_RangeRequested_NotModified()
var streamReader = new StreamReader(httpResponse.Body);
var body = streamReader.ReadToEndAsync().Result;
Assert.Equal(StatusCodes.Status304NotModified, httpResponse.StatusCode);
Assert.Equal(11, httpResponse.ContentLength);
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Empty(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public async Task WriteFileAsync_RangeRequested_PreconditionFailed()
var body = streamReader.ReadToEndAsync().Result;
Assert.Equal(StatusCodes.Status412PreconditionFailed, httpResponse.StatusCode);
Assert.Equal("bytes", httpResponse.Headers[HeaderNames.AcceptRanges]);
Assert.Equal(34, httpResponse.ContentLength);
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Empty(body);
Expand Down Expand Up @@ -271,7 +271,7 @@ public async Task WriteFileAsync_RangeRequested_NotModified()
var body = streamReader.ReadToEndAsync().Result;
Assert.Equal(StatusCodes.Status304NotModified, httpResponse.StatusCode);
Assert.Equal("bytes", httpResponse.Headers[HeaderNames.AcceptRanges]);
Assert.Equal(34, httpResponse.ContentLength);
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Empty(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public async Task WriteFileAsync_RangeRequested_PreconditionFailed()
var body = streamReader.ReadToEndAsync().Result;
Assert.Equal(StatusCodes.Status412PreconditionFailed, httpResponse.StatusCode);
Assert.Equal("bytes", httpResponse.Headers[HeaderNames.AcceptRanges]);
Assert.Equal(33, httpResponse.ContentLength);
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Empty(body);
Expand Down Expand Up @@ -355,7 +355,7 @@ public async Task WriteFileAsync_RangeRequested_NotModified()
var body = streamReader.ReadToEndAsync().Result;
Assert.Equal(StatusCodes.Status304NotModified, httpResponse.StatusCode);
Assert.Equal("bytes", httpResponse.Headers[HeaderNames.AcceptRanges]);
Assert.Equal(33, httpResponse.ContentLength);
Assert.Null(httpResponse.ContentLength);
Assert.Empty(httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Empty(body);
Expand Down

0 comments on commit bd8b4d8

Please sign in to comment.