Http3ServerExample and Http3ClientExample error
xtuyaowu opened this issue · 0 comments
/*
- Copyright 2020 The Netty Project
- The Netty Project licenses this file to you under the Apache License,
- version 2.0 (the "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at:
- https://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- License for the specific language governing permissions and limitations
- under the License.
*/
package io.netty.incubator.codec.http3.example;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.incubator.codec.http3.DefaultHttp3DataFrame;
import io.netty.incubator.codec.http3.DefaultHttp3HeadersFrame;
import io.netty.incubator.codec.http3.Http3;
import io.netty.incubator.codec.http3.Http3DataFrame;
import io.netty.incubator.codec.http3.Http3HeadersFrame;
import io.netty.incubator.codec.http3.Http3RequestStreamInboundHandler;
import io.netty.incubator.codec.http3.Http3ServerConnectionHandler;
import io.netty.incubator.codec.quic.InsecureQuicTokenHandler;
import io.netty.incubator.codec.quic.QuicChannel;
import io.netty.incubator.codec.quic.QuicSslContext;
import io.netty.incubator.codec.quic.QuicSslContextBuilder;
import io.netty.incubator.codec.quic.QuicStreamChannel;
import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
public final class Http3ServerExample {
private static final byte[] CONTENT = "Hello World!\r\n".getBytes(CharsetUtil.US_ASCII);
static final int PORT = 9999;
private Http3ServerExample() { }
public static void main(String... args) throws Exception {
int port;
// Allow to pass in the port so we can also use it to run h3spec against
if (args.length == 1) {
port = Integer.parseInt(args[0]);
} else {
port = PORT;
}
NioEventLoopGroup group = new NioEventLoopGroup(1);
SelfSignedCertificate cert = new SelfSignedCertificate();
QuicSslContext sslContext = QuicSslContextBuilder.forServer(cert.key(), null, cert.cert())
.applicationProtocols(Http3.supportedApplicationProtocols()).build();
ChannelHandler codec = Http3.newQuicServerCodecBuilder()
.sslContext(sslContext)
.maxIdleTimeout(5000, TimeUnit.HOURS)
.initialMaxData(10000000)
.initialMaxStreamDataBidirectionalLocal(1000000)
.initialMaxStreamDataBidirectionalRemote(1000000)
.initialMaxStreamsBidirectional(100)
.tokenHandler(InsecureQuicTokenHandler.INSTANCE)
.handler(new ChannelInitializer<QuicChannel>() {
@Override
protected void initChannel(QuicChannel ch) {
// Called for each connection
ch.pipeline().addLast(new Http3ServerConnectionHandler(
new ChannelInitializer<QuicStreamChannel>() {
// Called for each request-stream,
@Override
protected void initChannel(QuicStreamChannel ch) {
ch.pipeline().addLast(new Http3RequestStreamInboundHandler() {
@Override
protected void channelRead(ChannelHandlerContext ctx,
Http3HeadersFrame frame, boolean isLast) {
if (isLast) {
writeResponse(ctx);
}
ReferenceCountUtil.release(frame);
}
@Override
protected void channelRead(ChannelHandlerContext ctx,
Http3DataFrame frame, boolean isLast) {
if (isLast) {
writeResponse(ctx);
}
ReferenceCountUtil.release(frame);
}
private void writeResponse(ChannelHandlerContext ctx) {
for(int i = 0; i<1000; i++) {
String sendmessage = "Hello World "+i+"!\r\n";
byte[] CONTENTTest = sendmessage.getBytes(CharsetUtil.US_ASCII);
if(i == 0) {
Http3HeadersFrame headersFrame = new DefaultHttp3HeadersFrame();
headersFrame.headers().status("200");
headersFrame.headers().add("server", "netty");
headersFrame.headers().addInt("content-length", CONTENTTest.length);
ctx.write(headersFrame);
}
ctx.writeAndFlush(new DefaultHttp3DataFrame(
Unpooled.wrappedBuffer(CONTENTTest)));
//.addListener(QuicStreamChannel.SHUTDOWN_OUTPUT);
}
}
});
}
}));
}
}).build();
try {
Bootstrap bs = new Bootstrap();
Channel channel = bs.group(group)
.channel(NioDatagramChannel.class)
.handler(codec)
.bind(new InetSocketAddress(port)).sync().channel();
channel.closeFuture().sync();
} finally {
group.shutdownGracefully();
}
}
}
============================================
/*
- Copyright 2020 The Netty Project
- The Netty Project licenses this file to you under the Apache License,
- version 2.0 (the "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at:
- https://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- License for the specific language governing permissions and limitations
- under the License.
*/
package io.netty.incubator.codec.http3.example;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.incubator.codec.http3.DefaultHttp3HeadersFrame;
import io.netty.incubator.codec.http3.Http3;
import io.netty.incubator.codec.http3.Http3ClientConnectionHandler;
import io.netty.incubator.codec.http3.Http3DataFrame;
import io.netty.incubator.codec.http3.Http3HeadersFrame;
import io.netty.incubator.codec.http3.Http3RequestStreamFrame;
import io.netty.incubator.codec.http3.Http3RequestStreamInboundHandler;
import io.netty.incubator.codec.quic.QuicChannel;
import io.netty.incubator.codec.quic.QuicSslContext;
import io.netty.incubator.codec.quic.QuicSslContextBuilder;
import io.netty.incubator.codec.quic.QuicStreamChannel;
import io.netty.util.CharsetUtil;
import io.netty.util.NetUtil;
import io.netty.util.ReferenceCountUtil;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
public final class Http3ClientExample {
private Http3ClientExample() { }
public static void main(String... args) throws Exception {
NioEventLoopGroup group = new NioEventLoopGroup(1);
try {
QuicSslContext context = QuicSslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.applicationProtocols(Http3.supportedApplicationProtocols()).build();
ChannelHandler codec = Http3.newQuicClientCodecBuilder()
.sslContext(context)
.maxIdleTimeout(5000, TimeUnit.HOURS)
.initialMaxData(10000000)
.initialMaxStreamDataBidirectionalLocal(1000000)
.build();
Bootstrap bs = new Bootstrap();
Channel channel = bs.group(group)
.channel(NioDatagramChannel.class)
.handler(codec)
.bind(0).sync().channel();
QuicChannel quicChannel = QuicChannel.newBootstrap(channel)
.handler(new Http3ClientConnectionHandler())
.remoteAddress(new InetSocketAddress(NetUtil.LOCALHOST4, Http3ServerExample.PORT))
.connect()
.get();
QuicStreamChannel streamChannel = Http3.newRequestStream(quicChannel,
new Http3RequestStreamInboundHandler() {
@Override
protected void channelRead(ChannelHandlerContext ctx,
Http3HeadersFrame frame, boolean isLast) {
releaseFrameAndCloseIfLast(ctx, frame, isLast);
}
@Override
protected void channelRead(ChannelHandlerContext ctx,
Http3DataFrame frame, boolean isLast) {
System.err.print(frame.content().toString(CharsetUtil.US_ASCII));
releaseFrameAndCloseIfLast(ctx, frame, isLast);
}
private void releaseFrameAndCloseIfLast(ChannelHandlerContext ctx,
Http3RequestStreamFrame frame, boolean isLast) {
ReferenceCountUtil.release(frame);
if (isLast) {
ctx.close();
}
}
}).sync().getNow();
// Write the Header frame and send the FIN to mark the end of the request.
// After this its not possible anymore to write any more data.
Http3HeadersFrame frame = new DefaultHttp3HeadersFrame();
frame.headers().method("GET").path("/")
.authority(NetUtil.LOCALHOST4.getHostAddress() + ":" + Http3ServerExample.PORT)
.scheme("https");
streamChannel.writeAndFlush(frame)
.addListener(QuicStreamChannel.SHUTDOWN_OUTPUT).sync();
// Wait for the stream channel and quic channel to be closed (this will happen after we received the FIN).
// After this is done we will close the underlying datagram channel.
streamChannel.closeFuture().sync();
// After we received the response lets also close the underlying QUIC channel and datagram channel.
quicChannel.closeFuture().sync();
channel.closeFuture().sync();
} finally {
group.shutdownGracefully();
}
}
}
===============================================
io.netty.incubator.codec.http3.Http3Exception: Expected content-length 16 != 34.
at io.netty.incubator.codec.http3.Http3RequestStreamValidationUtils.verifyContentLength(Http3RequestStreamValidationUtils.java:152)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationUtils.validateDataFrameRead(Http3RequestStreamValidationUtils.java:97)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.channelRead(Http3RequestStreamValidationHandler.java:111)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.channelRead(Http3RequestStreamValidationHandler.java:34)
at io.netty.incubator.codec.http3.Http3FrameTypeInboundValidationHandler.channelRead(Http3FrameTypeInboundValidationHandler.java:37)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
at io.netty.incubator.codec.http3.Http3RequestStreamDecodeStateValidator.channelRead(Http3RequestStreamDecodeStateValidator.java:45)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:311)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:432)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.incubator.codec.http3.Http3FrameCodec.channelRead(Http3FrameCodec.java:122)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel$QuicStreamChannelUnsafe.recv(QuicheQuicStreamChannel.java:900)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel.readable(QuicheQuicStreamChannel.java:419)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.recvStream(QuicheQuicChannel.java:1377)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.connectionRecv(QuicheQuicChannel.java:1314)
at io.netty.incubator.codec.quic.QuicheQuicChannel.recv(QuicheQuicChannel.java:856)
at io.netty.incubator.codec.quic.QuicheQuicCodec.lambda$handlerAdded$0(QuicheQuicCodec.java:87)
at io.netty.incubator.codec.quic.QuicHeaderParser.parse(QuicHeaderParser.java:123)
at io.netty.incubator.codec.quic.QuicheQuicCodec.handleQuicPacket(QuicheQuicCodec.java:144)
at io.netty.incubator.codec.quic.QuicheQuicCodec.channelRead(QuicheQuicCodec.java:135)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:97)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)
14:07:05.765 [nioEventLoopGroup-2-1] ERROR io.netty.incubator.codec.http3.Http3RequestStreamInboundHandler - Caught Http3Exception on channel [id: 0x44242522, QuicStreamAddress{streamId=0}]
io.netty.incubator.codec.http3.Http3Exception: Expected content-length 16 != 34.
at io.netty.incubator.codec.http3.Http3RequestStreamValidationUtils.verifyContentLength(Http3RequestStreamValidationUtils.java:152)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationUtils.validateDataFrameRead(Http3RequestStreamValidationUtils.java:97)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.channelRead(Http3RequestStreamValidationHandler.java:111)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.channelRead(Http3RequestStreamValidationHandler.java:34)
at io.netty.incubator.codec.http3.Http3FrameTypeInboundValidationHandler.channelRead(Http3FrameTypeInboundValidationHandler.java:37)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
at io.netty.incubator.codec.http3.Http3RequestStreamDecodeStateValidator.channelRead(Http3RequestStreamDecodeStateValidator.java:45)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:311)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:432)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.incubator.codec.http3.Http3FrameCodec.channelRead(Http3FrameCodec.java:122)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel$QuicStreamChannelUnsafe.recv(QuicheQuicStreamChannel.java:900)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel.readable(QuicheQuicStreamChannel.java:419)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.recvStream(QuicheQuicChannel.java:1377)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.connectionRecv(QuicheQuicChannel.java:1314)
at io.netty.incubator.codec.quic.QuicheQuicChannel.recv(QuicheQuicChannel.java:856)
at io.netty.incubator.codec.quic.QuicheQuicCodec.lambda$handlerAdded$0(QuicheQuicCodec.java:87)
at io.netty.incubator.codec.quic.QuicHeaderParser.parse(QuicHeaderParser.java:123)
at io.netty.incubator.codec.quic.QuicheQuicCodec.handleQuicPacket(QuicheQuicCodec.java:144)
at io.netty.incubator.codec.quic.QuicheQuicCodec.channelRead(QuicheQuicCodec.java:135)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:97)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)
14:07:05.765 [nioEventLoopGroup-2-1] ERROR io.netty.incubator.codec.http3.Http3RequestStreamInboundHandler - Caught Http3Exception on channel [id: 0x44242522, QuicStreamAddress{streamId=0}]
io.netty.incubator.codec.http3.Http3Exception: Expected content-length 16 != 34.
at io.netty.incubator.codec.http3.Http3RequestStreamValidationUtils.verifyContentLength(Http3RequestStreamValidationUtils.java:152)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationUtils.validateDataFrameRead(Http3RequestStreamValidationUtils.java:97)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.channelRead(Http3RequestStreamValidationHandler.java:111)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.channelRead(Http3RequestStreamValidationHandler.java:34)
at io.netty.incubator.codec.http3.Http3FrameTypeInboundValidationHandler.channelRead(Http3FrameTypeInboundValidationHandler.java:37)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
at io.netty.incubator.codec.http3.Http3RequestStreamDecodeStateValidator.channelRead(Http3RequestStreamDecodeStateValidator.java:45)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:311)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:432)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.incubator.codec.http3.Http3FrameCodec.channelRead(Http3FrameCodec.java:122)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel$QuicStreamChannelUnsafe.recv(QuicheQuicStreamChannel.java:900)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel.readable(QuicheQuicStreamChannel.java:419)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.recvStream(QuicheQuicChannel.java:1377)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.connectionRecv(QuicheQuicChannel.java:1314)
at io.netty.incubator.codec.quic.QuicheQuicChannel.recv(QuicheQuicChannel.java:856)
at io.netty.incubator.codec.quic.QuicheQuicCodec.lambda$handlerAdded$0(QuicheQuicCodec.java:87)
at io.netty.incubator.codec.quic.QuicHeaderParser.parse(QuicHeaderParser.java:123)
at io.netty.incubator.codec.quic.QuicheQuicCodec.handleQuicPacket(QuicheQuicCodec.java:144)
at io.netty.incubator.codec.quic.QuicheQuicCodec.channelRead(QuicheQuicCodec.java:135)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:97)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)
14:07:05.765 [nioEventLoopGroup-2-1] ERROR io.netty.incubator.codec.http3.Http3RequestStreamInboundHandler - Caught Http3Exception on channel [id: 0x44242522, QuicStreamAddress{streamId=0}]
io.netty.incubator.codec.http3.Http3Exception: Expected content-length 16 != 34.
at io.netty.incubator.codec.http3.Http3RequestStreamValidationUtils.verifyContentLength(Http3RequestStreamValidationUtils.java:152)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationUtils.validateDataFrameRead(Http3RequestStreamValidationUtils.java:97)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.channelRead(Http3RequestStreamValidationHandler.java:111)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.channelRead(Http3RequestStreamValidationHandler.java:34)
at io.netty.incubator.codec.http3.Http3FrameTypeInboundValidationHandler.channelRead(Http3FrameTypeInboundValidationHandler.java:37)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
at io.netty.incubator.codec.http3.Http3RequestStreamDecodeStateValidator.channelRead(Http3RequestStreamDecodeStateValidator.java:45)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:311)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:432)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.incubator.codec.http3.Http3FrameCodec.channelRead(Http3FrameCodec.java:122)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel$QuicStreamChannelUnsafe.recv(QuicheQuicStreamChannel.java:900)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel.readable(QuicheQuicStreamChannel.java:419)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.recvStream(QuicheQuicChannel.java:1377)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.connectionRecv(QuicheQuicChannel.java:1314)
at io.netty.incubator.codec.quic.QuicheQuicChannel.recv(QuicheQuicChannel.java:856)
at io.netty.incubator.codec.quic.QuicheQuicCodec.lambda$handlerAdded$0(QuicheQuicCodec.java:87)
at io.netty.incubator.codec.quic.QuicHeaderParser.parse(QuicHeaderParser.java:123)
at io.netty.incubator.codec.quic.QuicheQuicCodec.handleQuicPacket(QuicheQuicCodec.java:144)
at io.netty.incubator.codec.quic.QuicheQuicCodec.channelRead(QuicheQuicCodec.java:135)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:97)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)
14:07:05.765 [nioEventLoopGroup-2-1] ERROR io.netty.incubator.codec.http3.Http3RequestStreamInboundHandler - Caught Http3Exception on channel [id: 0x44242522, QuicStreamAddress{streamId=0}]
io.netty.incubator.codec.http3.Http3Exception: Expected content-length 16 != 34.
how to use Http3HeadersFrame ?
if
private void writeResponse(ChannelHandlerContext ctx) {
for(int i = 0; i<1000; i++) {
String sendmessage = "Hello World "+i+"!\r\n";
byte[] CONTENTTest = sendmessage.getBytes(CharsetUtil.US_ASCII);
// if(i == 0) {
// Http3HeadersFrame headersFrame = new DefaultHttp3HeadersFrame();
// headersFrame.headers().status("200");
// headersFrame.headers().add("server", "netty");
// headersFrame.headers().addInt("content-length", CONTENTTest.length);
// ctx.write(headersFrame);
// }
Http3HeadersFrame headersFrame = new DefaultHttp3HeadersFrame();
headersFrame.headers().status("200");
headersFrame.headers().add("server", "netty");
headersFrame.headers().addInt("content-length", CONTENTTest.length);
ctx.write(headersFrame);
ctx.writeAndFlush(new DefaultHttp3DataFrame(
Unpooled.wrappedBuffer(CONTENTTest)));
//.addListener(QuicStreamChannel.SHUTDOWN_OUTPUT);
}
}
got error
io.netty.incubator.codec.http3.Http3Exception: Frame type unexpected
at io.netty.incubator.codec.http3.Http3CodecUtils.connectionError(Http3CodecUtils.java:249)
at io.netty.incubator.codec.http3.Http3FrameValidationUtils.frameTypeUnexpected(Http3FrameValidationUtils.java:92)
at io.netty.incubator.codec.http3.Http3RequestStreamEncodeStateValidator.write(Http3RequestStreamEncodeStateValidator.java:44)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:709)
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:792)
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:702)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.write(Http3RequestStreamValidationHandler.java:83)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.write(Http3RequestStreamValidationHandler.java:34)
at io.netty.incubator.codec.http3.Http3FrameTypeDuplexValidationHandler.write(Http3FrameTypeDuplexValidationHandler.java:38)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717)
at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764)
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:790)
at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:758)
at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:808)
at io.netty.incubator.codec.http3.example.Http3ServerExample$1$1$1.writeResponse(Http3ServerExample.java:118)
at io.netty.incubator.codec.http3.example.Http3ServerExample$1$1$1.channelRead(Http3ServerExample.java:95)
at io.netty.incubator.codec.http3.Http3RequestStreamInboundHandler.notifyLast(Http3RequestStreamInboundHandler.java:90)
at io.netty.incubator.codec.http3.Http3RequestStreamInboundHandler.userEventTriggered(Http3RequestStreamInboundHandler.java:71)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:346)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:332)
at io.netty.channel.AbstractChannelHandlerContext.fireUserEventTriggered(AbstractChannelHandlerContext.java:324)
at io.netty.incubator.codec.http3.Http3RequestStreamValidationHandler.userEventTriggered(Http3RequestStreamValidationHandler.java:131)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:346)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:332)
at io.netty.channel.AbstractChannelHandlerContext.fireUserEventTriggered(AbstractChannelHandlerContext.java:324)
at io.netty.channel.ChannelInboundHandlerAdapter.userEventTriggered(ChannelInboundHandlerAdapter.java:117)
at io.netty.handler.codec.ByteToMessageDecoder.userEventTriggered(ByteToMessageDecoder.java:365)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:346)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:332)
at io.netty.channel.AbstractChannelHandlerContext.fireUserEventTriggered(AbstractChannelHandlerContext.java:324)
at io.netty.channel.DefaultChannelPipeline$HeadContext.userEventTriggered(DefaultChannelPipeline.java:1428)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:346)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelPipeline.fireUserEventTriggered(DefaultChannelPipeline.java:913)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel$QuicStreamChannelUnsafe.closeOnRead(QuicheQuicStreamChannel.java:794)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel$QuicStreamChannelUnsafe.recv(QuicheQuicStreamChannel.java:911)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel.readable(QuicheQuicStreamChannel.java:419)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.recvStream(QuicheQuicChannel.java:1377)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.connectionRecv(QuicheQuicChannel.java:1314)
at io.netty.incubator.codec.quic.QuicheQuicChannel.recv(QuicheQuicChannel.java:856)
at io.netty.incubator.codec.quic.QuicheQuicCodec.lambda$handlerAdded$0(QuicheQuicCodec.java:87)
at io.netty.incubator.codec.quic.QuicHeaderParser.parse(QuicHeaderParser.java:123)
at io.netty.incubator.codec.quic.QuicheQuicCodec.handleQuicPacket(QuicheQuicCodec.java:144)
at io.netty.incubator.codec.quic.QuicheQuicCodec.channelRead(QuicheQuicCodec.java:135)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:97)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)
io.netty.incubator.codec.http3.Http3HeadersValidationException: Pseudo-header(s) included in trailers.
at io.netty.incubator.codec.http3.Http3HeadersSink.finish(Http3HeadersSink.java:63)
at io.netty.incubator.codec.http3.Http3FrameCodec.decodeHeaders(Http3FrameCodec.java:393)
at io.netty.incubator.codec.http3.Http3FrameCodec.decodeFrame(Http3FrameCodec.java:243)
at io.netty.incubator.codec.http3.Http3FrameCodec.decode(Http3FrameCodec.java:192)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:507)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:446)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.incubator.codec.http3.Http3FrameCodec.channelRead(Http3FrameCodec.java:122)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel$QuicStreamChannelUnsafe.recv(QuicheQuicStreamChannel.java:900)
at io.netty.incubator.codec.quic.QuicheQuicStreamChannel.readable(QuicheQuicStreamChannel.java:419)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.recvStream(QuicheQuicChannel.java:1377)
at io.netty.incubator.codec.quic.QuicheQuicChannel$QuicChannelUnsafe.connectionRecv(QuicheQuicChannel.java:1314)
at io.netty.incubator.codec.quic.QuicheQuicChannel.recv(QuicheQuicChannel.java:856)
at io.netty.incubator.codec.quic.QuicheQuicCodec.lambda$handlerAdded$0(QuicheQuicCodec.java:87)
at io.netty.incubator.codec.quic.QuicHeaderParser.parse(QuicHeaderParser.java:123)
at io.netty.incubator.codec.quic.QuicheQuicCodec.handleQuicPacket(QuicheQuicCodec.java:144)
at io.netty.incubator.codec.quic.QuicheQuicCodec.channelRead(QuicheQuicCodec.java:135)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:97)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)