Description
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" };
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
See aspnet/HttpAbstractions#382 for discussion.