Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not reorder HTTP header values #65249

Merged
merged 31 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1f717f8
Do not reorder HTTP header values
feiyun0112 Feb 12, 2022
02d168a
Merge branch 'main' into fix-63833
feiyun0112 Feb 12, 2022
04e4718
fix complie error
feiyun0112 Feb 13, 2022
c4f503b
make the changes @ danmoseley recommended
feiyun0112 Feb 15, 2022
f5b1cb0
make the changes @MihaZupan recommended
feiyun0112 Feb 16, 2022
542b448
Merge branch 'dotnet:main' into fix-63833
feiyun0112 Feb 19, 2022
2fd48a6
make the changes @MihaZupan recommended
feiyun0112 Feb 19, 2022
cf3716b
make the changes @MihaZupan recommended
feiyun0112 Feb 21, 2022
afd612a
make the changes @MihaZupan recommended
feiyun0112 Feb 28, 2022
92ac1a3
make the changes @MihaZupan recommended
feiyun0112 Mar 1, 2022
ad7aaf8
check array length
feiyun0112 Mar 1, 2022
6f5c6ac
fix unit test
feiyun0112 Mar 8, 2022
263fe0e
Update src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHead…
feiyun0112 Mar 9, 2022
7cf1a6b
Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/Http…
feiyun0112 Mar 9, 2022
dfa81e7
Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/Http…
feiyun0112 Mar 9, 2022
68a5b36
Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/Http…
feiyun0112 Mar 9, 2022
017a558
make the changes @MihaZupan recommended
feiyun0112 Mar 9, 2022
f7a4636
Merge branch 'fix-63833' of https://github.com/feiyun0112/runtime int…
feiyun0112 Mar 9, 2022
c69be94
Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/Cach…
feiyun0112 Mar 9, 2022
39c1a98
chang unit test
feiyun0112 Mar 11, 2022
1dcebc9
Merge branch 'fix-63833' of https://github.com/feiyun0112/runtime int…
feiyun0112 Mar 11, 2022
a969560
GetParsedValueLength
feiyun0112 Mar 11, 2022
3684810
fix build error
feiyun0112 Mar 12, 2022
876d130
Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/Cach…
feiyun0112 Mar 16, 2022
8904a36
Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/Http…
feiyun0112 Mar 16, 2022
c3cd0af
unit test
feiyun0112 Mar 16, 2022
ef11a8a
make changes @geoffkizer recommended
feiyun0112 Mar 17, 2022
8f69ba8
CloneAndAddValue for InvalidValues
feiyun0112 Mar 21, 2022
682d146
Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/Http…
feiyun0112 Mar 22, 2022
e50c36d
Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/Http…
feiyun0112 Mar 22, 2022
5badaae
Final nits
MihaZupan Mar 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ internal static int GetNextNonEmptyOrWhitespaceIndex(string input, int startInde
{
Debug.Assert(store != null);

object? storedValue = store.GetParsedValues(descriptor);
object? storedValue = store.GetSingleParsedValue(descriptor);
if (storedValue != null)
{
return (DateTimeOffset)storedValue;
Expand All @@ -304,7 +304,7 @@ internal static int GetNextNonEmptyOrWhitespaceIndex(string input, int startInde
{
Debug.Assert(store != null);

object? storedValue = store.GetParsedValues(descriptor);
object? storedValue = store.GetSingleParsedValue(descriptor);
if (storedValue != null)
{
return (TimeSpan)storedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class HttpContentHeaders : HttpHeaders

public ContentDispositionHeaderValue? ContentDisposition
{
get { return (ContentDispositionHeaderValue?)GetParsedValues(KnownHeaders.ContentDisposition.Descriptor); }
get { return (ContentDispositionHeaderValue?)GetSingleParsedValue(KnownHeaders.ContentDisposition.Descriptor); }
set { SetOrRemoveParsedValue(KnownHeaders.ContentDisposition.Descriptor, value); }
}

Expand All @@ -36,7 +36,7 @@ public long? ContentLength
get
{
// 'Content-Length' can only hold one value. So either we get 'null' back or a boxed long value.
object? storedValue = GetParsedValues(KnownHeaders.ContentLength.Descriptor);
object? storedValue = GetSingleParsedValue(KnownHeaders.ContentLength.Descriptor);

// Only try to calculate the length if the user didn't set the value explicitly using the setter.
if (!_contentLengthSet && (storedValue == null))
Expand Down Expand Up @@ -72,25 +72,25 @@ public long? ContentLength

public Uri? ContentLocation
{
get { return (Uri?)GetParsedValues(KnownHeaders.ContentLocation.Descriptor); }
get { return (Uri?)GetSingleParsedValue(KnownHeaders.ContentLocation.Descriptor); }
set { SetOrRemoveParsedValue(KnownHeaders.ContentLocation.Descriptor, value); }
}

public byte[]? ContentMD5
{
get { return (byte[]?)GetParsedValues(KnownHeaders.ContentMD5.Descriptor); }
get { return (byte[]?)GetSingleParsedValue(KnownHeaders.ContentMD5.Descriptor); }
set { SetOrRemoveParsedValue(KnownHeaders.ContentMD5.Descriptor, value); }
}

public ContentRangeHeaderValue? ContentRange
{
get { return (ContentRangeHeaderValue?)GetParsedValues(KnownHeaders.ContentRange.Descriptor); }
get { return (ContentRangeHeaderValue?)GetSingleParsedValue(KnownHeaders.ContentRange.Descriptor); }
set { SetOrRemoveParsedValue(KnownHeaders.ContentRange.Descriptor, value); }
}

public MediaTypeHeaderValue? ContentType
{
get { return (MediaTypeHeaderValue?)GetParsedValues(KnownHeaders.ContentType.Descriptor); }
get { return (MediaTypeHeaderValue?)GetSingleParsedValue(KnownHeaders.ContentType.Descriptor); }
set { SetOrRemoveParsedValue(KnownHeaders.ContentType.Descriptor, value); }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class HttpGeneralHeaders

public CacheControlHeaderValue? CacheControl
{
get { return (CacheControlHeaderValue?)_parent.GetParsedValues(KnownHeaders.CacheControl.Descriptor); }
get { return (CacheControlHeaderValue?)_parent.GetSingleParsedValue(KnownHeaders.CacheControl.Descriptor); }
set { _parent.SetOrRemoveParsedValue(KnownHeaders.CacheControl.Descriptor, value); }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void CopyTo(T[] array!!, int arrayIndex)
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
}

object? storeValue = _store.GetParsedValues(_descriptor);
object? storeValue = _store.GetParsedAndInvalidValues(_descriptor);
feiyun0112 marked this conversation as resolved.
Show resolved Hide resolved

if (storeValue == null)
{
Expand Down Expand Up @@ -122,8 +122,8 @@ public bool Remove(T item)

public IEnumerator<T> GetEnumerator()
{
object? storeValue = _store.GetParsedValues(_descriptor);
return storeValue is null ?
object? storeValue = _store.GetParsedAndInvalidValues(_descriptor);
return storeValue is null || storeValue is HttpHeaders.InvalidValue ?
((IEnumerable<T>)Array.Empty<T>()).GetEnumerator() : // use singleton empty array enumerator
Iterate(storeValue);

Expand All @@ -134,6 +134,10 @@ static IEnumerator<T> Iterate(object storeValue)
// We have multiple values. Iterate through the values and return them.
foreach (object item in storeValues)
{
if (item is HttpHeaders.InvalidValue)
{
continue;
}
Debug.Assert(item is T);
yield return (T)item;
}
Expand Down Expand Up @@ -178,7 +182,7 @@ private int GetCount()
{
// This is an O(n) operation.

object? storeValue = _store.GetParsedValues(_descriptor);
object? storeValue = _store.GetParsedAndInvalidValues(_descriptor);

if (storeValue == null)
{
Expand All @@ -189,11 +193,23 @@ private int GetCount()

if (storeValues == null)
{
return 1;
if (storeValue is not HttpHeaders.InvalidValue)
{
return 1;
}
return 0;
}
else
{
return storeValues.Count;
int count = 0;
foreach (object item in storeValues)
{
if (item is not HttpHeaders.InvalidValue)
{
count++;
}
}
return count;
}
}
}
Expand Down
Loading