diff --git a/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/HeaderDictionaryExtensions.cs b/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/HeaderDictionaryExtensions.cs
index 5cc06484..0e31660d 100644
--- a/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/HeaderDictionaryExtensions.cs
+++ b/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/HeaderDictionaryExtensions.cs
@@ -39,7 +39,7 @@ public static void AppendCommaSeparatedValues(this IHeaderDictionary headers, st
/// the associated values from the collection separated into individual values, or StringValues.Empty if the key is not present.
public static string[] GetCommaSeparatedValues(this IHeaderDictionary headers, string key)
{
- return ParsingHelpers.GetHeaderSplit(headers, key).ToArray();
+ return ParsingHelpers.GetHeaderSplit(headers, key);
}
///
diff --git a/src/Microsoft.AspNetCore.Http.Abstractions/Internal/ParsingHelpers.cs b/src/Microsoft.AspNetCore.Http.Abstractions/Internal/ParsingHelpers.cs
index 185fc40a..c3bcdefd 100644
--- a/src/Microsoft.AspNetCore.Http.Abstractions/Internal/ParsingHelpers.cs
+++ b/src/Microsoft.AspNetCore.Http.Abstractions/Internal/ParsingHelpers.cs
@@ -153,7 +153,7 @@ public static void AppendHeaderUnmodified(IHeaderDictionary headers, string key,
throw new ArgumentNullException(nameof(key));
}
- if (values.Count == 0)
+ if (values.IsNull)
{
return;
}
diff --git a/src/Microsoft.AspNetCore.Http/HeaderDictionary.cs b/src/Microsoft.AspNetCore.Http/HeaderDictionary.cs
index bc0b7a26..ed3b3ba6 100644
--- a/src/Microsoft.AspNetCore.Http/HeaderDictionary.cs
+++ b/src/Microsoft.AspNetCore.Http/HeaderDictionary.cs
@@ -74,7 +74,7 @@ public StringValues this[string key]
}
ThrowIfReadOnly();
- if (StringValues.IsNullOrEmpty(value))
+ if (value.ToString().Length == 0)
{
Store?.Remove(key);
}
@@ -177,8 +177,11 @@ public void Add(KeyValuePair item)
throw new ArgumentNullException("The key is null");
}
ThrowIfReadOnly();
- EnsureStore(1);
- Store.Add(item.Key, item.Value);
+ if (item.Value.ToString().Length > 0)
+ {
+ EnsureStore(1);
+ Store.Add(item.Key, item.Value);
+ }
}
///
@@ -193,8 +196,11 @@ public void Add(string key, StringValues value)
throw new ArgumentNullException(nameof(key));
}
ThrowIfReadOnly();
- EnsureStore(1);
- Store.Add(key, value);
+ if (value.ToString().Length > 0)
+ {
+ EnsureStore(1);
+ Store.Add(key, value);
+ }
}
///
diff --git a/src/Microsoft.AspNetCore.WebUtilities/KeyValueAccumulator.cs b/src/Microsoft.AspNetCore.WebUtilities/KeyValueAccumulator.cs
index 5ae402e5..49ec9f2a 100644
--- a/src/Microsoft.AspNetCore.WebUtilities/KeyValueAccumulator.cs
+++ b/src/Microsoft.AspNetCore.WebUtilities/KeyValueAccumulator.cs
@@ -22,7 +22,7 @@ public void Append(string key, string value)
StringValues values;
if (_accumulator.TryGetValue(key, out values))
{
- if (values.Count == 0)
+ if (values.IsNull)
{
// Marker entry for this key to indicate entry already in expanding list dictionary
_expandingAccumulator[key].Add(value);