public void ClientRequestStreamDependencyInHttpMessageFlow() { this.BootstrapEnv(1, 2, 1); string text = "hello world big time data!"; IByteBuffer content = Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes(text)); string text2 = "hello world big time data...number 2!!"; IByteBuffer content2 = Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes(text2)); IFullHttpRequest request = new DefaultFullHttpRequest(DotNetty.Codecs.Http.HttpVersion.Http11, HttpMethod.Put, "/some/path/resource", content, true); IFullHttpMessage request2 = new DefaultFullHttpRequest(DotNetty.Codecs.Http.HttpVersion.Http11, HttpMethod.Put, "/some/path/resource2", content2, true); try { HttpHeaders httpHeaders = request.Headers; httpHeaders.SetInt(HttpConversionUtil.ExtensionHeaderNames.StreamId, 3); httpHeaders.SetInt(HttpHeaderNames.ContentLength, text.Length); httpHeaders.SetShort(HttpConversionUtil.ExtensionHeaderNames.StreamWeight, 16); HttpHeaders httpHeaders2 = request2.Headers; httpHeaders2.SetInt(HttpConversionUtil.ExtensionHeaderNames.StreamId, 5); httpHeaders2.SetInt(HttpConversionUtil.ExtensionHeaderNames.StreamDependencyId, 3); httpHeaders2.SetShort(HttpConversionUtil.ExtensionHeaderNames.StreamWeight, 123); httpHeaders2.SetInt(HttpHeaderNames.ContentLength, text2.Length); var http2Headers = new DefaultHttp2Headers() { Method = new AsciiString("PUT"), Path = new AsciiString("/some/path/resource"), }; var http2Headers2 = new DefaultHttp2Headers() { Method = new AsciiString("PUT"), Path = new AsciiString("/some/path/resource2"), }; Http2TestUtil.RunInChannel(this.clientChannel, () => { this.clientHandler.Encoder.WriteHeadersAsync(this.CtxClient(), 3, http2Headers, 0, false, this.NewPromiseClient()); this.clientHandler.Encoder.WriteHeadersAsync(this.CtxClient(), 5, http2Headers2, 3, 123, true, 0, false, this.NewPromiseClient()); this.clientChannel.Flush(); // Headers are queued in the flow controller and so flush them. this.clientHandler.Encoder.WriteDataAsync(this.CtxClient(), 3, content.RetainedDuplicate(), 0, true, this.NewPromiseClient()); this.clientHandler.Encoder.WriteDataAsync(this.CtxClient(), 5, content2.RetainedDuplicate(), 0, true, this.NewPromiseClient()); this.clientChannel.Flush(); }); this.AwaitRequests(); var httpObjectCaptor = new ArgumentCaptor <IFullHttpMessage>(); this.serverListener.Verify(x => x.MessageReceived(It.Is <IHttpObject>(v => httpObjectCaptor.Capture((IFullHttpMessage)v))), Times.Exactly(2)); this.capturedRequests = httpObjectCaptor.GetAllValues(); Assert.Equal(request, (IFullHttpRequest)this.capturedRequests[0]); Assert.Equal(request2, this.capturedRequests[1]); } finally { request.Release(); request2.Release(); } }
private static IHttp2Headers HeadersOfSize(int minSize) { AsciiString singleByte = new AsciiString(new byte[] { 0 }, false); DefaultHttp2Headers headers = new DefaultHttp2Headers(false); for (int size = 0; size < minSize; size += 2) { headers.Add(singleByte, singleByte); } return(headers); }
public void StripTEHeadersExcludingTrailers() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.Add(HttpHeaderNames.Te, HttpHeaderValues.Gzip); inHeaders.Add(HttpHeaderNames.Te, HttpHeaderValues.Trailers); var output = new DefaultHttp2Headers(); HttpConversionUtil.ToHttp2Headers(inHeaders, output); Assert.Same(HttpHeaderValues.Trailers, output.Get(HttpHeaderNames.Te, null)); }
/** * Sends a "Hello World" DATA frame to the client. */ private static void SendResponse(IChannelHandlerContext context, IByteBuffer payload) { // Send a frame for the response status IHttp2Headers headers = new DefaultHttp2Headers() { Status = HttpResponseStatus.OK.CodeAsText }; context.WriteAsync(new DefaultHttp2HeadersFrame(headers)); context.WriteAsync(new DefaultHttp2DataFrame(payload, true)); }
private static IHttp2Headers Headers() { var headers = new DefaultHttp2Headers(false); headers.Method = AsciiString.Of("GET"); headers.Scheme = AsciiString.Of("https"); headers.Authority = AsciiString.Of("example.org"); headers.Path = AsciiString.Of("/some/path/resource2"); headers.Add(Http2TestUtil.RandomString(), Http2TestUtil.RandomString()); return(headers); }
public void StripConnectionHeadersAndNominees() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.Add(HttpHeaderNames.Connection, "foo"); inHeaders.Add((AsciiString)"foo", "bar"); var output = new DefaultHttp2Headers(); HttpConversionUtil.ToHttp2Headers(inHeaders, output); Assert.True(output.IsEmpty); }
private static IHttp2Headers LargeHeaders() { DefaultHttp2Headers headers = new DefaultHttp2Headers(false); for (int i = 0; i < 100; ++i) { string key = "this-is-a-test-header-key-" + i; string value = "this-is-a-test-header-value-" + i; headers.Add(AsciiString.Of(key), AsciiString.Of(value)); } return(headers); }
private static IByteBuffer Encode(params byte[][] entries) { HpackEncoder hpackEncoder = Http2TestUtil.NewTestEncoder(); var output = Unpooled.Buffer(); var http2Headers = new DefaultHttp2Headers(false); for (int ix = 0; ix < entries.Length;) { http2Headers.Add(new AsciiString(entries[ix++], false), new AsciiString(entries[ix++], false)); } hpackEncoder.EncodeHeaders(3 /* randomly chosen */, output, http2Headers, NeverSensitiveDetector.Instance); return(output); }
/** * Sends a "Hello World" DATA frame to the client. */ void SendResponse(IChannelHandlerContext ctx, int streamId, IByteBuffer payload) { // Send a frame for the response status IHttp2Headers headers = new DefaultHttp2Headers() { Status = HttpResponseStatus.OK.CodeAsText }; this.Encoder.WriteHeadersAsync(ctx, streamId, headers, 0, false, ctx.NewPromise()); this.Encoder.WriteDataAsync(ctx, streamId, payload, 0, true, ctx.NewPromise()); // no need to call flush as channelReadComplete(...) will take care of it. }
public void AddHttp2ToHttpHeadersCombinesCookies() { var inHeaders = new DefaultHttp2Headers(); inHeaders.Add((AsciiString)"yes", (AsciiString)"no"); inHeaders.Add(HttpHeaderNames.Cookie, (AsciiString)"foo=bar"); inHeaders.Add(HttpHeaderNames.Cookie, (AsciiString)"bax=baz"); HttpHeaders outHeaders = new DefaultHttpHeaders(); HttpConversionUtil.AddHttp2ToHttpHeaders(5, inHeaders, outHeaders, HttpVersion.Http11, false, false); Assert.Equal("no", outHeaders.Get((AsciiString)"yes", null)); Assert.Equal("foo=bar; bax=baz", outHeaders.Get(HttpHeaderNames.Cookie, null)); }
private static IHttp2Headers NewHeaders() { var headers = new DefaultHttp2Headers(); headers.Add(AsciiString.Of("name1"), new[] { AsciiString.Of("value1"), AsciiString.Of("value2") }); headers.Method = AsciiString.Of("POST"); headers.Add(AsciiString.Of("2name"), AsciiString.Of("value3")); headers.Path = AsciiString.Of("/index.html"); headers.Status = AsciiString.Of("200"); headers.Authority = AsciiString.Of("netty.io"); headers.Add(AsciiString.Of("name3"), AsciiString.Of("value4")); headers.Scheme = AsciiString.Of("https"); return(headers); }
public void TestSetHeadersOrdersPseudoHeadersCorrectly() { var headers = NewHeaders(); var other = new DefaultHttp2Headers(); other.Add((AsciiString)"name2", (AsciiString)"value2"); other.Authority = (AsciiString)"foo"; headers.Set(other); VerifyPseudoHeadersFirst(headers); Assert.Equal(other.Size, headers.Size); Assert.Equal("foo", headers.Authority); Assert.Equal("value2", headers.Get((AsciiString)"name2", null)); }
public void StripConnectionNomineesWithCsv() { HttpHeaders inHeaders = new DefaultHttpHeaders(); inHeaders.Add(HttpHeaderNames.Connection, "foo, bar"); inHeaders.Add((AsciiString)"foo", "baz"); inHeaders.Add((AsciiString)"bar", "qux"); inHeaders.Add((AsciiString)"hello", "world"); var output = new DefaultHttp2Headers(); HttpConversionUtil.ToHttp2Headers(inHeaders, output); Assert.Equal(1, output.Size); Assert.Same("world", output.Get((AsciiString)"hello", null).ToString()); }
static IHttp2Headers Http1HeadersToHttp2Headers(IFullHttpRequest request) { IHttp2Headers http2Headers = new DefaultHttp2Headers() { Method = HttpMethod.Get.AsciiName, Path = AsciiString.Of(request.Uri), Scheme = HttpScheme.Http.Name }; if (request.Headers.TryGet(HttpHeaderNames.Host, out var host)) { http2Headers.Authority = host; } return(http2Headers); }
private static IHttp2Headers Headers() { var headers = new DefaultHttp2Headers(false); headers.Method = new AsciiString("GET"); headers.Scheme = new AsciiString("https"); headers.Authority = new AsciiString("example.org"); headers.Path = new AsciiString("/some/path/resource2"); headers.Add(new AsciiString("accept"), new AsciiString("image/png")); headers.Add(new AsciiString("cache-control"), new AsciiString("no-cache")); headers.Add(new AsciiString("custom"), new AsciiString("value1")); headers.Add(new AsciiString("custom"), new AsciiString("value2")); headers.Add(new AsciiString("custom"), new AsciiString("value3")); headers.Add(new AsciiString("custom"), new AsciiString("custom4")); headers.Add(Http2TestUtil.RandomString(), Http2TestUtil.RandomString()); return(headers); }
public void FailedWhenContinuationFrameNotFollowHeaderFrame() { var input = Unpooled.Buffer(); try { var headers0 = new DefaultHttp2Headers(); headers0.Add((AsciiString)"foo", (AsciiString)"bar"); this.WriteContinuationFrame(input, 1, headers0, new Http2Flags().EndOfHeaders(true)); Assert.Throws <Http2Exception>(() => frameReader.ReadFrame(this.ctx.Object, input, this.listener.Object)); } finally { input.Release(); } }
public void TestSetAllOrdersPseudoHeadersCorrectly() { var headers = NewHeaders(); var other = new DefaultHttp2Headers(); other.Add((AsciiString)"name2", (AsciiString)"value2"); other.Authority = (AsciiString)"foo"; int headersSizeBefore = headers.Size; headers.SetAll(other); VerifyPseudoHeadersFirst(headers); VerifyAllPseudoHeadersPresent(headers); Assert.Equal(headersSizeBefore + 1, headers.Size); Assert.Equal((AsciiString)"foo", headers.Authority); Assert.Equal((AsciiString)"value2", headers.Get((AsciiString)"name2", null)); }
public void ClientRequestTrailingHeaders() { this.BootstrapEnv(1, 1, 1); string text = "some data"; IByteBuffer content = Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes(text)); IFullHttpRequest request = new DefaultFullHttpRequest(DotNetty.Codecs.Http.HttpVersion.Http11, HttpMethod.Get, "/some/path/resource2", content, true); try { HttpHeaders httpHeaders = request.Headers; httpHeaders.SetInt(HttpConversionUtil.ExtensionHeaderNames.StreamId, 3); httpHeaders.SetInt(HttpHeaderNames.ContentLength, text.Length); httpHeaders.SetShort(HttpConversionUtil.ExtensionHeaderNames.StreamWeight, 16); HttpHeaders trailingHeaders = request.TrailingHeaders; trailingHeaders.Set(AsciiString.Of("Foo"), AsciiString.Of("goo")); trailingHeaders.Set(AsciiString.Of("fOo2"), AsciiString.Of("goo2")); trailingHeaders.Add(AsciiString.Of("foO2"), AsciiString.Of("goo3")); var http2Headers = new DefaultHttp2Headers() { Method = new AsciiString("GET"), Path = new AsciiString("/some/path/resource2"), }; IHttp2Headers http2Headers2 = new DefaultHttp2Headers(); http2Headers2.Set(new AsciiString("foo"), new AsciiString("goo")); http2Headers2.Set(new AsciiString("foo2"), new AsciiString("goo2")); http2Headers2.Add(new AsciiString("foo2"), new AsciiString("goo3")); Http2TestUtil.RunInChannel(this.clientChannel, () => { this.clientHandler.Encoder.WriteHeadersAsync(this.CtxClient(), 3, http2Headers, 0, false, this.NewPromiseClient()); this.clientHandler.Encoder.WriteDataAsync(this.CtxClient(), 3, content.RetainedDuplicate(), 0, false, this.NewPromiseClient()); this.clientHandler.Encoder.WriteHeadersAsync(this.CtxClient(), 3, http2Headers2, 0, true, this.NewPromiseClient()); this.clientChannel.Flush(); }); this.AwaitRequests(); var requestCaptor = new ArgumentCaptor <IFullHttpMessage>(); this.serverListener.Verify(x => x.MessageReceived(It.Is <IHttpObject>(v => requestCaptor.Capture((IFullHttpMessage)v)))); this.capturedRequests = requestCaptor.GetAllValues(); Assert.Equal(request, (IFullHttpRequest)this.capturedRequests[0]); } finally { request.Release(); } }
public void WriteLargeHeaderWithPadding() { int streamId = 1; IHttp2Headers headers = new DefaultHttp2Headers() { Method = HttpMethod.Get.AsciiName, Path = (AsciiString)"/", Authority = (AsciiString)"foo.com", Scheme = (AsciiString)"https" }; headers = DummyHeaders(headers, 20); _http2HeadersEncoder.Configuration.SetMaxHeaderListSize(int.MaxValue); _frameWriter.HeadersConfiguration.SetMaxHeaderListSize(int.MaxValue); _frameWriter.SetMaxFrameSize(Http2CodecUtil.MaxFrameSizeLowerBound); _frameWriter.WriteHeadersAsync(_ctx.Object, streamId, headers, 5, true, _promise); byte[] expectedPayload = BuildLargeHeaderPayload(streamId, headers, (byte)4, Http2CodecUtil.MaxFrameSizeLowerBound); // First frame: HEADER(length=0x4000, flags=0x09) Assert.Equal(Http2CodecUtil.MaxFrameSizeLowerBound, _outbound.ReadUnsignedMedium()); Assert.Equal(0x01, _outbound.ReadByte()); Assert.Equal(0x09, _outbound.ReadByte()); // 0x01 + 0x08 Assert.Equal(streamId, _outbound.ReadInt()); byte[] firstPayload = new byte[Http2CodecUtil.MaxFrameSizeLowerBound]; _outbound.ReadBytes(firstPayload); int remainPayloadLength = expectedPayload.Length - Http2CodecUtil.MaxFrameSizeLowerBound; // Second frame: CONTINUATION(length=remainPayloadLength, flags=0x04) Assert.Equal(remainPayloadLength, _outbound.ReadUnsignedMedium()); Assert.Equal(0x09, _outbound.ReadByte()); Assert.Equal(0x04, _outbound.ReadByte()); Assert.Equal(streamId, _outbound.ReadInt()); byte[] secondPayload = new byte[remainPayloadLength]; _outbound.ReadBytes(secondPayload); Assert.Equal(expectedPayload.Slice(0, firstPayload.Length), firstPayload); Assert.Equal(expectedPayload.Slice(firstPayload.Length, expectedPayload.Length - firstPayload.Length), secondPayload); }
public void OriginFormRequestTargetHandled() { this.BootstrapEnv(2, 1, 0); IFullHttpRequest request = new DefaultFullHttpRequest(DotNetty.Codecs.Http.HttpVersion.Http11, HttpMethod.Get, "/where?q=now&f=then#section1"); HttpHeaders httpHeaders = request.Headers; httpHeaders.SetInt(HttpConversionUtil.ExtensionHeaderNames.StreamId, 5); httpHeaders.Set(HttpConversionUtil.ExtensionHeaderNames.Scheme, "http"); var http2Headers = new DefaultHttp2Headers() { Method = new AsciiString("GET"), Path = new AsciiString("/where?q=now&f=then#section1"), Scheme = new AsciiString("http") }; var writePromise = this.NewPromise(); this.VerifyHeadersOnly(http2Headers, writePromise, this.clientChannel.WriteAndFlushAsync(request, writePromise)); }
public void AuthorityFormRequestTargetHandled() { this.BootstrapEnv(2, 1, 0); IFullHttpRequest request = new DefaultFullHttpRequest(DotNetty.Codecs.Http.HttpVersion.Http11, HttpMethod.Connect, "http://www.example.com:80"); HttpHeaders httpHeaders = request.Headers; httpHeaders.SetInt(HttpConversionUtil.ExtensionHeaderNames.StreamId, 5); var http2Headers = new DefaultHttp2Headers() { Method = new AsciiString("CONNECT"), Path = new AsciiString("/"), //Authority = new AsciiString("www.example.com:80"), // Uri 忽略默认端口 80 Authority = new AsciiString("www.example.com"), Scheme = new AsciiString("http") }; var writePromise = this.NewPromise(); this.VerifyHeadersOnly(http2Headers, writePromise, this.clientChannel.WriteAndFlushAsync(request, writePromise)); }
public void AbsoluteFormRequestTargetHandledFromRequestTargetUri() { this.BootstrapEnv(2, 1, 0); IFullHttpRequest request = new DefaultFullHttpRequest(DotNetty.Codecs.Http.HttpVersion.Http11, HttpMethod.Get, "http://[email protected]:5555/pub/WWW/TheProject.html"); HttpHeaders httpHeaders = request.Headers; httpHeaders.SetInt(HttpConversionUtil.ExtensionHeaderNames.StreamId, 5); var http2Headers = new DefaultHttp2Headers() { Method = new AsciiString("GET"), Path = new AsciiString("/pub/WWW/TheProject.html"), Authority = new AsciiString("www.example.org:5555"), Scheme = new AsciiString("http") }; var writePromise = this.NewPromise(); this.VerifyHeadersOnly(http2Headers, writePromise, this.clientChannel.WriteAndFlushAsync(request, writePromise)); }
public void TestDecodeResponseHeaders() { EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(false)); IHttp2Headers headers = new DefaultHttp2Headers(); headers.Scheme = HttpScheme.Http.Name; headers.Status = HttpResponseStatus.OK.CodeAsText; Assert.True(ch.WriteInbound(new DefaultHttp2HeadersFrame(headers))); IHttpResponse response = ch.ReadInbound <IHttpResponse>(); Assert.Equal(HttpResponseStatus.OK, response.Status); Assert.Equal(HttpVersion.Http11, response.ProtocolVersion); Assert.False(response is IFullHttpResponse); Assert.True(HttpUtil.IsTransferEncodingChunked(response)); Assert.Null(ch.ReadInbound <object>()); Assert.False(ch.Finish()); }
public void ClientRequestSingleHeaderCookieSplitIntoMultipleEntries() { this.BootstrapEnv(1, 1, 1); IFullHttpRequest request = new DefaultFullHttpRequest(DotNetty.Codecs.Http.HttpVersion.Http11, HttpMethod.Get, "/some/path/resource2", true); try { HttpHeaders httpHeaders = request.Headers; httpHeaders.Set(HttpConversionUtil.ExtensionHeaderNames.Scheme, "https"); httpHeaders.Set(HttpHeaderNames.Host, "example.org"); httpHeaders.SetInt(HttpConversionUtil.ExtensionHeaderNames.StreamId, 3); httpHeaders.SetInt(HttpHeaderNames.ContentLength, 0); httpHeaders.Set(HttpHeaderNames.Cookie, "a=b; c=d; e=f"); httpHeaders.SetShort(HttpConversionUtil.ExtensionHeaderNames.StreamWeight, 16); var http2Headers = new DefaultHttp2Headers() { Method = new AsciiString("GET"), Scheme = new AsciiString("https"), Authority = new AsciiString("example.org"), Path = new AsciiString("/some/path/resource2"), }; http2Headers.Add(HttpHeaderNames.Cookie, (AsciiString)"a=b"); http2Headers.Add(HttpHeaderNames.Cookie, (AsciiString)"c=d"); http2Headers.Add(HttpHeaderNames.Cookie, (AsciiString)"e=f"); Http2TestUtil.RunInChannel(this.clientChannel, () => { this.clientHandler.Encoder.WriteHeadersAsync(this.CtxClient(), 3, http2Headers, 0, true, this.NewPromiseClient()); this.clientChannel.Flush(); }); this.AwaitRequests(); var requestCaptor = new ArgumentCaptor <IFullHttpMessage>(); this.serverListener.Verify(x => x.MessageReceived(It.Is <IHttpObject>(v => requestCaptor.Capture((IFullHttpMessage)v)))); this.capturedRequests = requestCaptor.GetAllValues(); Assert.Equal(request, (IFullHttpRequest)this.capturedRequests[0]); } finally { request.Release(); } }
public void WriteLargeHeaders() { int streamId = 1; IHttp2Headers headers = new DefaultHttp2Headers(); headers.Method = (AsciiString)"GET"; headers.Path = (AsciiString)"/"; headers.Authority = (AsciiString)"foo.com"; headers.Scheme = (AsciiString)"https"; headers = DummyHeaders(headers, 20); _http2HeadersEncoder.Configuration.SetMaxHeaderListSize(int.MaxValue); _frameWriter.HeadersConfiguration.SetMaxHeaderListSize(int.MaxValue); _frameWriter.SetMaxFrameSize(Http2CodecUtil.MaxFrameSizeLowerBound); _frameWriter.WriteHeadersAsync(_ctx.Object, streamId, headers, 0, true, _promise); byte[] expectedPayload = HeaderPayload(streamId, headers); // First frame: HEADER(length=0x4000, flags=0x01) Assert.Equal(Http2CodecUtil.MaxFrameSizeLowerBound, _outbound.ReadUnsignedMedium()); Assert.Equal(0x01, _outbound.ReadByte()); Assert.Equal(0x01, _outbound.ReadByte()); Assert.Equal(streamId, _outbound.ReadInt()); byte[] firstPayload = new byte[Http2CodecUtil.MaxFrameSizeLowerBound]; _outbound.ReadBytes(firstPayload); int remainPayloadLength = expectedPayload.Length - Http2CodecUtil.MaxFrameSizeLowerBound; // Second frame: CONTINUATION(length=remainPayloadLength, flags=0x04) Assert.Equal(remainPayloadLength, _outbound.ReadUnsignedMedium()); Assert.Equal(0x09, _outbound.ReadByte()); Assert.Equal(0x04, _outbound.ReadByte()); Assert.Equal(streamId, _outbound.ReadInt()); byte[] secondPayload = new byte[remainPayloadLength]; _outbound.ReadBytes(secondPayload); Assert.True(PlatformDependent.ByteArrayEquals(expectedPayload, 0, firstPayload, 0, firstPayload.Length)); Assert.True(PlatformDependent.ByteArrayEquals(expectedPayload, firstPayload.Length, secondPayload, 0, secondPayload.Length)); }
public void UnknownPseudoHeader() { IByteBuffer input = Unpooled.Buffer(200); try { HpackEncoder hpackEncoder = new HpackEncoder(true); IHttp2Headers toEncode = new DefaultHttp2Headers(); toEncode.Add((AsciiString)":test", (AsciiString)"1"); hpackEncoder.EncodeHeaders(1, input, toEncode, NeverSensitiveDetector.Instance); IHttp2Headers decoded = new DefaultHttp2Headers(); Assert.Throws <StreamException>(() => hpackDecoder.Decode(1, input, decoded, true)); } finally { input.Release(); } }
public void ClientRequestSingleHeaderNonAsciiShouldThrow() { this.BootstrapEnv(1, 1, 1); var http2Headers = new DefaultHttp2Headers() { Method = new AsciiString("GET"), Scheme = new AsciiString("https"), Authority = new AsciiString("example.org"), Path = new AsciiString("/some/path/resource2"), }; http2Headers.Add(new AsciiString(Encoding.UTF8.GetBytes("çã"), true), new AsciiString(Encoding.UTF8.GetBytes("Ãã"), true)); Http2TestUtil.RunInChannel(this.clientChannel, () => { this.clientHandler.Encoder.WriteHeadersAsync(this.CtxClient(), 3, http2Headers, 0, true, this.NewPromiseClient()); this.clientChannel.Flush(); }); this.AwaitResponses(); Assert.True(Http2Exception.IsStreamError(this.clientException)); }
public void TestDecodeLargerThanMaxHeaderListSizeUpdatesDynamicTable() { IByteBuffer input = Unpooled.Buffer(300); try { hpackDecoder.SetMaxHeaderListSize(200); HpackEncoder hpackEncoder = new HpackEncoder(true); // encode headers that are slightly larger than maxHeaderListSize IHttp2Headers toEncode = new DefaultHttp2Headers(); toEncode.Add((AsciiString)"test_1", (AsciiString)"1"); toEncode.Add((AsciiString)"test_2", (AsciiString)"2"); toEncode.Add((AsciiString)"long", (AsciiString)"A".PadRight(100, 'A')); //string.Format("{0,0100:d}", 0).Replace('0', 'A') toEncode.Add((AsciiString)"test_3", (AsciiString)"3"); hpackEncoder.EncodeHeaders(1, input, toEncode, NeverSensitiveDetector.Instance); // decode the headers, we should get an exception IHttp2Headers decoded = new DefaultHttp2Headers(); Assert.Throws <HeaderListSizeException>(() => hpackDecoder.Decode(1, input, decoded, true)); // but the dynamic table should have been updated, so that later blocks // can refer to earlier headers input.Clear(); // 0x80, "indexed header field representation" // index 62, the first (most recent) dynamic table entry input.WriteByte(0x80 | 62); IHttp2Headers decoded2 = new DefaultHttp2Headers(); hpackDecoder.Decode(1, input, decoded2, true); IHttp2Headers golden = new DefaultHttp2Headers(); golden.Add((AsciiString)"test_3", (AsciiString)"3"); Assert.Equal(golden, decoded2); } finally { input.Release(); } }
private void TestDecodeFullResponseHeaders0(bool withStreamId) { EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(false)); IHttp2Headers headers = new DefaultHttp2Headers(); headers.Scheme = HttpScheme.Http.Name; headers.Status = HttpResponseStatus.OK.CodeAsText; IHttp2HeadersFrame frame = new DefaultHttp2HeadersFrame(headers, true); if (withStreamId) { frame.Stream = new TestHttp2FrameStream(); } Assert.True(ch.WriteInbound(frame)); IFullHttpResponse response = ch.ReadInbound <IFullHttpResponse>(); try { Assert.Equal(HttpResponseStatus.OK, response.Status); Assert.Equal(HttpVersion.Http11, response.ProtocolVersion); Assert.Equal(0, response.Content.ReadableBytes); Assert.True(response.TrailingHeaders.IsEmpty); Assert.False(HttpUtil.IsTransferEncodingChunked(response)); if (withStreamId) { Assert.Equal(1, response.Headers.GetInt(HttpConversionUtil.ExtensionHeaderNames.StreamId, 0)); } } finally { response.Release(); } Assert.Null(ch.ReadInbound <object>()); Assert.False(ch.Finish()); }
public void TestDowngradeHeaders() { EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(true)); IHttp2Headers headers = new DefaultHttp2Headers { Path = (AsciiString)"/", Method = (AsciiString)"GET" }; Assert.True(ch.WriteInbound(new DefaultHttp2HeadersFrame(headers))); var request = ch.ReadInbound <IHttpRequest>(); Assert.Equal("/", request.Uri); Assert.Equal(HttpMethod.Get, request.Method); Assert.Equal(HttpVersion.Http11, request.ProtocolVersion); Assert.False(request is IFullHttpRequest); Assert.True(HttpUtil.IsTransferEncodingChunked(request)); Assert.Null(ch.ReadInbound <object>()); Assert.False(ch.Finish()); }