You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 20, 2018. It is now read-only.
A new struct Microsoft.Framework.Primitives.StringValues has been introduced to streamline handling of values that may be empty, single strings, or multiple strings. The value is implicitly convertable to and from string and string[], and also provides helpers like Concat and IsNullOrEmpty.
The type is now used in request and response headers, query values, and form values. As such there have been some API changes in IHeaderDictionary and IReadableStringCollection (used in Form and Query). The indexer is now the primary API for these collections since the presence and plurality are taken care of by StringValues.
Examples:
string combineValue = httpContext.Request.Headers["header1];
if (string.IsNullOrEmpty(combineValue)) // ...
var values = httpContext.Request.Headers["header1"];
if (StringValues.IsNullOrEmpty(values)) // ...
httpContext.Response.Headers["CustomHeader1"] = "singleValue";
httpContext.Response.Headers["CustomHeader2"] = new[] { "firstValue", "secondValue" };
This abstraction is certainly better than having bare string[] everywhere. However, I do have concerns that extreme optimizations like using a struct to avoid any sort of allocation (which is only beneficial when you have a single string) is driving some of the type's implementation and design and could lead to a lot of confusion. That is unless the struct is implemented with full value semantics. For example, one would expect all of the following to compare equal when they don't:
newStringValues("foo").Equals(newStringValues("foo"))// => true
new StringValues("foo").Equals(newStringValues(new[]{"foo"}))// => false
new StringValues(new[]{"foo"}).Equals(newStringValues(new[]{"foo"}))// => false
What's more, if StringValues is initialized with an string array then that array can be modified after, yielding to more confusion.
We are closing this issue because no further action is planned for this issue. If you still have any issues or questions, please log a new issue with any additional details that you have.
A new struct Microsoft.Framework.Primitives.StringValues has been introduced to streamline handling of values that may be empty, single strings, or multiple strings. The value is implicitly convertable to and from string and string[], and also provides helpers like Concat and IsNullOrEmpty.
https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.Framework.Primitives/StringValues.cs
The type is now used in request and response headers, query values, and form values. As such there have been some API changes in IHeaderDictionary and IReadableStringCollection (used in Form and Query). The indexer is now the primary API for these collections since the presence and plurality are taken care of by StringValues.
Examples:
Also note that some APIs from IHeaderDictionary have been moved to extension methods in the Microsoft.AspNet.Http.Extensions package. See https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.Http.Extensions/HeaderDictionaryExtensions.cs
The text was updated successfully, but these errors were encountered: