public void Initialize_ChangeHeadersSource_EnumeratorUsesNewSource() { var responseHeaders = new HttpResponseHeaders(); responseHeaders.Append("Name1", "Value1"); responseHeaders.Append("Name2", "Value2-1"); responseHeaders.Append("Name2", "Value2-2"); var e = new Http2HeadersEnumerator(); e.Initialize(responseHeaders); Assert.True(e.MoveNext()); Assert.Equal("Name1", e.Current.Key); Assert.Equal("Value1", e.Current.Value); Assert.Equal(-1, e.HPackStaticTableId); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-1", e.Current.Value); Assert.Equal(-1, e.HPackStaticTableId); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-2", e.Current.Value); Assert.Equal(-1, e.HPackStaticTableId); var responseTrailers = new HttpResponseTrailers { HeaderGrpcStatus = "1" }; responseTrailers.Append("Name1", "Value1"); responseTrailers.Append("Name2", "Value2-1"); responseTrailers.Append("Name2", "Value2-2"); e.Initialize(responseTrailers); Assert.True(e.MoveNext()); Assert.Equal("Grpc-Status", e.Current.Key); Assert.Equal("1", e.Current.Value); Assert.Equal(-1, e.HPackStaticTableId); Assert.True(e.MoveNext()); Assert.Equal("Name1", e.Current.Key); Assert.Equal("Value1", e.Current.Value); Assert.Equal(-1, e.HPackStaticTableId); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-1", e.Current.Value); Assert.Equal(-1, e.HPackStaticTableId); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-2", e.Current.Value); Assert.Equal(-1, e.HPackStaticTableId); Assert.False(e.MoveNext()); }
public void CanIterateOverResponseHeaders() { var responseHeaders = new HttpResponseHeaders { ContentLength = 9, HeaderAcceptRanges = "AcceptRanges!", HeaderAge = new StringValues(new[] { "1", "2" }), HeaderDate = "Date!" }; responseHeaders.Append("Name1", "Value1"); responseHeaders.Append("Name2", "Value2-1"); responseHeaders.Append("Name2", "Value2-2"); responseHeaders.Append("Name3", "Value3"); var e = new Http2HeadersEnumerator(); e.Initialize(responseHeaders); var headers = GetNormalizedHeaders(e); Assert.Equal(new[] { new KeyValuePair <string, string>("Date", "Date!"), new KeyValuePair <string, string>("Accept-Ranges", "AcceptRanges!"), new KeyValuePair <string, string>("Age", "1"), new KeyValuePair <string, string>("Age", "2"), new KeyValuePair <string, string>("Content-Length", "9"), new KeyValuePair <string, string>("Name1", "Value1"), new KeyValuePair <string, string>("Name2", "Value2-1"), new KeyValuePair <string, string>("Name2", "Value2-2"), new KeyValuePair <string, string>("Name3", "Value3"), }, headers); }
public void GlobalSetup() { _knownSingleValueResponseHeaders = new HttpResponseHeaders { HeaderServer = "Value", HeaderDate = "Value", HeaderContentType = "Value", HeaderSetCookie = "Value" }; _knownMultipleValueResponseHeaders = new HttpResponseHeaders { HeaderServer = new StringValues(new[] { "One", "Two" }), HeaderDate = new StringValues(new[] { "One", "Two" }), HeaderContentType = new StringValues(new[] { "One", "Two" }), HeaderSetCookie = new StringValues(new[] { "One", "Two" }) }; _unknownSingleValueResponseHeaders = new HttpResponseHeaders(); _unknownSingleValueResponseHeaders.Append("One", "Value"); _unknownSingleValueResponseHeaders.Append("Two", "Value"); _unknownSingleValueResponseHeaders.Append("Three", "Value"); _unknownSingleValueResponseHeaders.Append("Four", "Value"); _unknownMultipleValueResponseHeaders = new HttpResponseHeaders(); _unknownMultipleValueResponseHeaders.Append("One", new StringValues(new[] { "One", "Two" })); _unknownMultipleValueResponseHeaders.Append("Two", new StringValues(new[] { "One", "Two" })); _unknownMultipleValueResponseHeaders.Append("Three", new StringValues(new[] { "One", "Two" })); _unknownMultipleValueResponseHeaders.Append("Four", new StringValues(new[] { "One", "Two" })); _enumerator = new Http2HeadersEnumerator(); }
public void BeginEncodeHeaders_ExcludedHeaders_NotAddedToTable(string headerName, bool neverIndex) { Span <byte> buffer = new byte[1024 * 16]; var headers = new HttpResponseHeaders(); headers.Append(headerName, "1"); var enumerator = new Http2HeadersEnumerator(); enumerator.Initialize(headers); var hpackEncoder = new DynamicHPackEncoder(maxHeaderTableSize: Http2PeerSettings.DefaultHeaderTableSize); Assert.True(HPackHeaderWriter.BeginEncodeHeaders(hpackEncoder, enumerator, buffer, out _)); if (neverIndex) { Assert.Equal(0x10, buffer[0] & 0x10); } else { Assert.Equal(0, buffer[0] & 0x40); } Assert.Empty(GetHeaderEntries(hpackEncoder)); }
public void GlobalSetup() { _http2HeadersEnumerator = new Http2HeadersEnumerator(); _hpackEncoder = new DynamicHPackEncoder(); _buffer = new byte[1024 * 1024]; _knownResponseHeaders = new HttpResponseHeaders(); var knownHeaders = (IHeaderDictionary)_knownResponseHeaders; knownHeaders.Server = "Kestrel"; knownHeaders.ContentType = "application/json"; knownHeaders.Date = "Date!"; knownHeaders.ContentLength = 0; knownHeaders.AcceptRanges = "Ranges!"; knownHeaders.TransferEncoding = "Encoding!"; knownHeaders.Via = "Via!"; knownHeaders.Vary = "Vary!"; knownHeaders.WWWAuthenticate = "Authenticate!"; knownHeaders.LastModified = "Modified!"; knownHeaders.Expires = "Expires!"; knownHeaders.Age = "Age!"; _unknownResponseHeaders = new HttpResponseHeaders(); for (var i = 0; i < 10; i++) { _unknownResponseHeaders.Append("Unknown" + i, "Value" + i); } }
public void GlobalSetup() { _http2HeadersEnumerator = new Http2HeadersEnumerator(); _hpackEncoder = new HPackEncoder(); _buffer = new byte[1024 * 1024]; _knownResponseHeaders = new HttpResponseHeaders { HeaderServer = "Kestrel", HeaderContentType = "application/json", HeaderDate = "Date!", HeaderContentLength = "0", HeaderAcceptRanges = "Ranges!", HeaderTransferEncoding = "Encoding!", HeaderVia = "Via!", HeaderVary = "Vary!", HeaderWWWAuthenticate = "Authenticate!", HeaderLastModified = "Modified!", HeaderExpires = "Expires!", HeaderAge = "Age!" }; _unknownResponseHeaders = new HttpResponseHeaders(); for (var i = 0; i < 10; i++) { _unknownResponseHeaders.Append("Unknown" + i, "Value" + i); } }
public void CanIterateOverResponseHeaders() { var responseHeaders = new HttpResponseHeaders { ContentLength = 9, HeaderAcceptRanges = "AcceptRanges!", HeaderAge = new StringValues(new[] { "1", "2" }), HeaderDate = "Date!", HeaderGrpcEncoding = "Identity!" }; responseHeaders.Append("Name1", "Value1"); responseHeaders.Append("Name2", "Value2-1"); responseHeaders.Append("Name2", "Value2-2"); responseHeaders.Append("Name3", "Value3"); var e = new Http2HeadersEnumerator(); e.Initialize(responseHeaders); var headers = GetNormalizedHeaders(e); Assert.Equal(new[] { CreateHeaderResult(H2StaticTable.Date, "Date", "Date!"), CreateHeaderResult(-1, "Grpc-Encoding", "Identity!"), CreateHeaderResult(H2StaticTable.AcceptRanges, "Accept-Ranges", "AcceptRanges!"), CreateHeaderResult(H2StaticTable.Age, "Age", "1"), CreateHeaderResult(H2StaticTable.Age, "Age", "2"), CreateHeaderResult(H2StaticTable.ContentLength, "Content-Length", "9"), CreateHeaderResult(-1, "Name1", "Value1"), CreateHeaderResult(-1, "Name2", "Value2-1"), CreateHeaderResult(-1, "Name2", "Value2-2"), CreateHeaderResult(-1, "Name3", "Value3"), }, headers); }
public void BeginEncodeHeaders_HeaderExceedHeaderTableSize_NoIndexAndNoHeaderEntry() { Span <byte> buffer = new byte[1024 * 16]; var headers = new HttpResponseHeaders(); headers.Append("x-Custom", new string('!', (int)Http2PeerSettings.DefaultHeaderTableSize)); var enumerator = new Http2HeadersEnumerator(); enumerator.Initialize(headers); var hpackEncoder = new DynamicHPackEncoder(); Assert.True(HPackHeaderWriter.BeginEncodeHeaders(200, hpackEncoder, enumerator, buffer, out var length)); Assert.Empty(GetHeaderEntries(hpackEncoder)); }
public void Initialize_ChangeHeadersSource_EnumeratorUsesNewSource() { var responseHeaders = new HttpResponseHeaders(); responseHeaders.Append("Name1", "Value1"); responseHeaders.Append("Name2", "Value2-1"); responseHeaders.Append("Name2", "Value2-2"); var e = new Http3HeadersEnumerator(); e.Initialize(responseHeaders); Assert.True(e.MoveNext()); Assert.Equal("Name1", e.Current.Key); Assert.Equal("Value1", e.Current.Value); var(index, matchedValue) = e.GetQPackStaticTableId(); Assert.Equal(-1, index); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-1", e.Current.Value); (index, matchedValue) = e.GetQPackStaticTableId(); Assert.Equal(-1, index); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-2", e.Current.Value); (index, matchedValue) = e.GetQPackStaticTableId(); Assert.Equal(-1, index); var responseTrailers = (IHeaderDictionary) new HttpResponseTrailers(); responseTrailers.GrpcStatus = "1"; responseTrailers.Append("Name1", "Value1"); responseTrailers.Append("Name2", "Value2-1"); responseTrailers.Append("Name2", "Value2-2"); e.Initialize(responseTrailers); Assert.True(e.MoveNext()); Assert.Equal("Grpc-Status", e.Current.Key); Assert.Equal("1", e.Current.Value); (index, matchedValue) = e.GetQPackStaticTableId(); Assert.Equal(-1, index); Assert.True(e.MoveNext()); Assert.Equal("Name1", e.Current.Key); Assert.Equal("Value1", e.Current.Value); (index, matchedValue) = e.GetQPackStaticTableId(); Assert.Equal(-1, index); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-1", e.Current.Value); (index, matchedValue) = e.GetQPackStaticTableId(); Assert.Equal(-1, index); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-2", e.Current.Value); (index, matchedValue) = e.GetQPackStaticTableId(); Assert.Equal(-1, index); Assert.False(e.MoveNext()); }