diff --git a/src/Microsoft.Net.Http.Server/RequestProcessing/Response.cs b/src/Microsoft.Net.Http.Server/RequestProcessing/Response.cs index 534529e198..628d910c5e 100644 --- a/src/Microsoft.Net.Http.Server/RequestProcessing/Response.cs +++ b/src/Microsoft.Net.Http.Server/RequestProcessing/Response.cs @@ -451,7 +451,7 @@ namespace Microsoft.Net.Http.Server _boundaryType = BoundaryType.ContentLength; // ComputeLeftToWrite checks for HEAD requests when setting _leftToWrite _expectedBodyLength = responseContentLength.Value; - if (responseContentLength.Value == writeCount && !isHeadRequest) + if (_expectedBodyLength == writeCount && !isHeadRequest) { // A single write with the whole content-length. Http.Sys will set the content-length for us in this scenario. // If we don't remove it then range requests served from cache will have two. diff --git a/test/Microsoft.Net.Http.Server.FunctionalTests/ResponseCachingTests.cs b/test/Microsoft.Net.Http.Server.FunctionalTests/ResponseCachingTests.cs index 5a062f878d..b3a3b1da74 100644 --- a/test/Microsoft.Net.Http.Server.FunctionalTests/ResponseCachingTests.cs +++ b/test/Microsoft.Net.Http.Server.FunctionalTests/ResponseCachingTests.cs @@ -291,6 +291,8 @@ namespace Microsoft.Net.Http.Server context.Response.ContentLength = 10; context.Response.CacheTtl = TimeSpan.FromSeconds(10); context.Response.Body.Write(new byte[10], 0, 10); + // Http.Sys will add this for us + Assert.Null(context.Response.ContentLength); context.Dispose(); var response = await responseTask; @@ -320,6 +322,8 @@ namespace Microsoft.Net.Http.Server context.Response.ContentLength = 10; context.Response.CacheTtl = TimeSpan.FromSeconds(10); await context.Response.Body.WriteAsync(new byte[10], 0, 10); + // Http.Sys will add this for us + Assert.Null(context.Response.ContentLength); context.Dispose(); var response = await responseTask; @@ -416,6 +420,8 @@ namespace Microsoft.Net.Http.Server context.Response.ContentLength = 10; context.Response.CacheTtl = TimeSpan.FromSeconds(10); context.Response.Body.Write(new byte[10], 0, 10); + // Http.Sys will add this for us + Assert.Null(context.Response.ContentLength); context.Dispose(); var response = await responseTask; @@ -478,6 +484,8 @@ namespace Microsoft.Net.Http.Server context.Response.ContentLength =_fileLength; context.Response.CacheTtl = TimeSpan.FromSeconds(10); await context.Response.SendFileAsync(_absoluteFilePath, 0, null, CancellationToken.None); + // Http.Sys will add this for us + Assert.Null(context.Response.ContentLength); context.Dispose(); var response = await responseTask;