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

Commit a7e7044

Browse files
author
Cesar Blum Silveira
committed
Set FrameResponseHeaders._contentLength to null when Content-Length header is removed.
1 parent 1d3b71d commit a7e7044

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,6 +3404,7 @@ protected override bool RemoveFast(string key)
34043404
{
34053405
if (((_bits & 2048L) != 0))
34063406
{
3407+
_contentLength = null;
34073408
_bits &= ~2048L;
34083409
_headers._ContentLength = StringValues.Empty;
34093410
return true;
@@ -3700,6 +3701,7 @@ protected override void ClearFast()
37003701
{
37013702
_bits = 0;
37023703
_headers = default(HeaderReferences);
3704+
_contentLength = null;
37033705
MaybeUnknown?.Clear();
37043706
}
37053707

@@ -8358,6 +8360,7 @@ protected override bool RemoveFast(string key)
83588360
{
83598361
if (((_bits & 2048L) != 0))
83608362
{
8363+
_contentLength = null;
83618364
_bits &= ~2048L;
83628365
_headers._ContentLength = StringValues.Empty;
83638366
_headers._rawContentLength = null;
@@ -8609,6 +8612,7 @@ protected override void ClearFast()
86098612
{
86108613
_bits = 0;
86118614
_headers = default(HeaderReferences);
8615+
_contentLength = null;
86128616
MaybeUnknown?.Clear();
86138617
}
86148618

test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,29 @@ public void ContentLengthValueCanBeReadAsLongAfterAssigningHeader()
201201

202202
Assert.Equal(42, headers.HeaderContentLengthValue);
203203
}
204+
205+
[Fact]
206+
public void ContentLengthValueClearedWhenHeaderIsRemoved()
207+
{
208+
var headers = new FrameResponseHeaders();
209+
headers.HeaderContentLength = "42";
210+
var dictionary = (IDictionary<string, StringValues>)headers;
211+
212+
dictionary.Remove("Content-Length");
213+
214+
Assert.Equal(null, headers.HeaderContentLengthValue);
215+
}
216+
217+
[Fact]
218+
public void ContentLengthValueClearedWhenHeadersCleared()
219+
{
220+
var headers = new FrameResponseHeaders();
221+
headers.HeaderContentLength = "42";
222+
var dictionary = (IDictionary<string, StringValues>)headers;
223+
224+
dictionary.Clear();
225+
226+
Assert.Equal(null, headers.HeaderContentLengthValue);
227+
}
204228
}
205229
}

tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ protected override bool RemoveFast(string key)
361361
if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase))
362362
{{
363363
if ({header.TestBit()})
364-
{{
364+
{{{If(header.Identifier == "ContentLength", () => $@"
365+
_contentLength = null;")}
365366
{header.ClearBit()};
366367
_headers._{header.Identifier} = StringValues.Empty;{(header.EnhancedSetter == false ? "" : $@"
367368
_headers._raw{header.Identifier} = null;")}
@@ -381,6 +382,7 @@ protected override void ClearFast()
381382
{{
382383
_bits = 0;
383384
_headers = default(HeaderReferences);
385+
_contentLength = null;
384386
MaybeUnknown?.Clear();
385387
}}
386388

0 commit comments

Comments
 (0)