static QPackDecoderBenchmark() { var headers = new HttpResponseHeaders(); var enumerator = new Http3HeadersEnumerator(); AddLargeHeader(headers, 'a'); enumerator.Initialize(headers); _headerFieldLine_LargeLiteralValue = GenerateHeaderBytes(enumerator); headers.Reset(); AddLargeHeader(headers, 'a'); AddLargeHeader(headers, 'b'); AddLargeHeader(headers, 'c'); AddLargeHeader(headers, 'd'); AddLargeHeader(headers, 'e'); enumerator.Initialize(headers); _headerFieldLine_LargeLiteralValue_Multiple = GenerateHeaderBytes(enumerator); headers.Reset(); ((IHeaderDictionary)headers).ContentLength = 0; ((IHeaderDictionary)headers).ContentType = "application/json"; ((IHeaderDictionary)headers).Age = "0"; ((IHeaderDictionary)headers).AcceptRanges = "bytes"; ((IHeaderDictionary)headers).AccessControlAllowOrigin = "*"; enumerator.Initialize(headers); _headerFieldLine_Static_Multiple = GenerateHeaderBytes(enumerator);
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); Assert.Equal(-1, e.QPackStaticTableId); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-1", e.Current.Value); Assert.Equal(-1, e.QPackStaticTableId); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-2", e.Current.Value); Assert.Equal(-1, e.QPackStaticTableId); 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); Assert.Equal(-1, e.QPackStaticTableId); Assert.True(e.MoveNext()); Assert.Equal("Name1", e.Current.Key); Assert.Equal("Value1", e.Current.Value); Assert.Equal(-1, e.QPackStaticTableId); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-1", e.Current.Value); Assert.Equal(-1, e.QPackStaticTableId); Assert.True(e.MoveNext()); Assert.Equal("Name2", e.Current.Key); Assert.Equal("Value2-2", e.Current.Value); Assert.Equal(-1, e.QPackStaticTableId); Assert.False(e.MoveNext()); }
public void CanIterateOverResponseTrailers() { var responseTrailers = (IHeaderDictionary) new HttpResponseTrailers(); responseTrailers.ContentLength = 9; responseTrailers.ETag = "ETag!"; responseTrailers.Append("Name1", "Value1"); responseTrailers.Append("Name2", "Value2-1"); responseTrailers.Append("Name2", "Value2-2"); responseTrailers.Append("Name3", "Value3"); var e = new Http3HeadersEnumerator(); e.Initialize(responseTrailers); var headers = GetNormalizedHeaders(e); Assert.Equal(new[] { CreateHeaderResult(7, "ETag", "ETag!"), CreateHeaderResult(-1, "Name1", "Value1"), CreateHeaderResult(-1, "Name2", "Value2-1"), CreateHeaderResult(-1, "Name2", "Value2-2"), CreateHeaderResult(-1, "Name3", "Value3"), }, headers); }
public void CanIterateOverResponseHeaders() { var responseHeaders = (IHeaderDictionary) new HttpResponseHeaders(); responseHeaders.ContentLength = 9; responseHeaders.AcceptRanges = "AcceptRanges!"; responseHeaders.Age = new StringValues(new[] { "1", "2" }); responseHeaders.Date = "Date!"; responseHeaders.GrpcEncoding = "Identity!"; responseHeaders.Append("Name1", "Value1"); responseHeaders.Append("Name2", "Value2-1"); responseHeaders.Append("Name2", "Value2-2"); responseHeaders.Append("Name3", "Value3"); var e = new Http3HeadersEnumerator(); e.Initialize(responseHeaders); var headers = GetNormalizedHeaders(e); Assert.Equal(new[] { CreateHeaderResult(6, "Date", "Date!"), CreateHeaderResult(32, "Accept-Ranges", "AcceptRanges!"), CreateHeaderResult(2, "Age", "1"), CreateHeaderResult(2, "Age", "2"), CreateHeaderResult(-1, "Grpc-Encoding", "Identity!"), CreateHeaderResult(4, "Content-Length", "9"), CreateHeaderResult(-1, "Name1", "Value1"), CreateHeaderResult(-1, "Name2", "Value2-1"), CreateHeaderResult(-1, "Name2", "Value2-2"), CreateHeaderResult(-1, "Name3", "Value3"), }, headers); }
internal Http3HeadersEnumerator GetHeadersEnumerator(IEnumerable <KeyValuePair <string, string> > headers) { var dictionary = headers .GroupBy(g => g.Key) .ToDictionary(g => g.Key, g => new StringValues(g.Select(values => values.Value).ToArray())); var headersEnumerator = new Http3HeadersEnumerator(); headersEnumerator.Initialize(dictionary); return(headersEnumerator); }
public void BeginEncodeHeaders_StatusWithIndexedValue_ExpectedLength(int statusCode) { Span <byte> buffer = new byte[1024 * 16]; var totalHeaderSize = 0; var headers = new HttpResponseHeaders(); var enumerator = new Http3HeadersEnumerator(); enumerator.Initialize(headers); Assert.True(QPackHeaderWriter.BeginEncodeHeaders(statusCode, enumerator, buffer, ref totalHeaderSize, out var length)); length -= 2; // Remove prefix Assert.True(length <= 2, "Indexed header should be encoded into 1 or 2 bytes"); }
public void BeginEncodeHeaders_StatusWithIndexedValue_WriteIndex() { Span <byte> buffer = new byte[1024 * 16]; var totalHeaderSize = 0; var headers = new HttpResponseHeaders(); var enumerator = new Http3HeadersEnumerator(); enumerator.Initialize(headers); Assert.True(QPackHeaderWriter.BeginEncodeHeaders(200, enumerator, buffer, ref totalHeaderSize, out var length)); var result = buffer.Slice(0, length).ToArray(); var hex = BitConverter.ToString(result); Assert.Equal("00-00-D9", hex); }
public void BeginEncodeHeaders_NoStatus_NonStaticKey_WriteFullNameAndFullValue() { Span <byte> buffer = new byte[1024 * 16]; var headers = (IHeaderDictionary) new HttpResponseHeaders(); headers.Translate = "private"; var totalHeaderSize = 0; var enumerator = new Http3HeadersEnumerator(); enumerator.Initialize(headers); Assert.True(QPackHeaderWriter.BeginEncodeHeaders(enumerator, buffer, ref totalHeaderSize, out var length)); var result = buffer.Slice(2, length - 2).ToArray(); var hex = BitConverter.ToString(result); Assert.Equal("37-02-74-72-61-6E-73-6C-61-74-65-07-70-72-69-76-61-74-65", hex); }
public void BeginEncodeHeaders_StaticKeyAndValue_WriteIndex() { Span <byte> buffer = new byte[1024 * 16]; var headers = (IHeaderDictionary) new HttpResponseHeaders(); headers.ContentType = "application/json"; var totalHeaderSize = 0; var enumerator = new Http3HeadersEnumerator(); enumerator.Initialize(headers); Assert.True(QPackHeaderWriter.BeginEncodeHeaders(enumerator, buffer, ref totalHeaderSize, out var length)); var result = buffer.Slice(2, length - 2).ToArray(); // trim prefix var hex = BitConverter.ToString(result); Assert.Equal("EE", hex); }
public void BeginEncodeHeaders_StaticKey_WriteStaticNameAndFullValue() { Span <byte> buffer = new byte[1024 * 16]; var headers = (IHeaderDictionary) new HttpResponseHeaders(); headers.ContentType = "application/custom"; var totalHeaderSize = 0; var enumerator = new Http3HeadersEnumerator(); enumerator.Initialize(headers); Assert.True(QPackHeaderWriter.BeginEncodeHeaders(enumerator, buffer, ref totalHeaderSize, out var length)); var result = buffer.Slice(2, length - 2).ToArray(); var hex = BitConverter.ToString(result); Assert.Equal("5F-1D-12-61-70-70-6C-69-63-61-74-69-6F-6E-2F-63-75-73-74-6F-6D", hex); }
public void BeginEncodeHeaders_NonStaticKey_WriteFullNameAndFullValue_CustomHeader() { Span <byte> buffer = new byte[1024 * 16]; var headers = (IHeaderDictionary) new HttpResponseHeaders(); headers["new-header"] = "value"; var totalHeaderSize = 0; var enumerator = new Http3HeadersEnumerator(); enumerator.Initialize(headers); Assert.True(QPackHeaderWriter.BeginEncodeHeaders(enumerator, buffer, ref totalHeaderSize, out var length)); var result = buffer.Slice(2, length - 2).ToArray(); // trim prefix var hex = BitConverter.ToString(result); Assert.Equal("37-03-6E-65-77-2D-68-65-61-64-65-72-05-76-61-6C-75-65", hex); }