public void GetCommaSeparatedValues_WorksForUnquotedHeaderValuesEndingWithSpace() { var headers = new HeaderDictionary { { "Via", "value " }, }; var result = headers.GetCommaSeparatedValues("Via"); Assert.Equal(new[] { "value " }, result); }
public void EmptyQuotedHeaderSegmentsAreIgnored() { var headers = new HeaderDictionary( new Dictionary <string, StringValues>(StringComparer.OrdinalIgnoreCase) { { "Header1", "Value1,\"\",,Value2" }, }); var result = headers.GetCommaSeparatedValues("Header1"); Assert.Equal(new[] { "Value1", "Value2" }, result); }
public void EmptyHeaderSegmentsAreIgnored(IEnumerable <string> segments) { var header = string.Join(",", segments); var headers = new HeaderDictionary( new Dictionary <string, StringValues>(StringComparer.OrdinalIgnoreCase) { { "Header1", header }, }); var result = headers.GetCommaSeparatedValues("Header1"); var expectedResult = segments.Where(s => !string.IsNullOrEmpty(s)); Assert.Equal(expectedResult, result); }
/// <summary> /// Overrides the default order of compression from Smidge, since Brotli is super slow (~10 seconds for backoffice.js) /// </summary> /// <param name="headers"></param> /// <returns></returns> public CompressionType GetClientCompression(IDictionary <string, StringValues> headers) { CompressionType type = CompressionType.None; if (headers is not IHeaderDictionary headerDictionary) { headerDictionary = new HeaderDictionary(headers.Count); foreach ((var key, StringValues stringValues) in headers) { headerDictionary[key] = stringValues; } } var acceptEncoding = headerDictionary.GetCommaSeparatedValues(HeaderNames.AcceptEncoding); if (acceptEncoding.Length > 0) { // Prefer in order: GZip, Deflate, Brotli. for (var i = 0; i < acceptEncoding.Length; i++) { var encoding = acceptEncoding[i].Trim(); var parsed = CompressionType.Parse(encoding); // Not pack200-gzip. if (parsed == CompressionType.GZip) { return(CompressionType.GZip); } if (parsed == CompressionType.Deflate) { type = CompressionType.Deflate; } // Brotli is typically last in the accept encoding header. if (type != CompressionType.Deflate && parsed == CompressionType.Brotli) { type = CompressionType.Brotli; } } } return(type); }