1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.http3;
17
18 import io.netty.channel.ChannelHandlerContext;
19 import io.netty.channel.ChannelInboundHandlerAdapter;
20 import io.netty.channel.socket.ChannelInputShutdownEvent;
21 import io.netty.handler.codec.quic.QuicException;
22 import io.netty.handler.codec.quic.QuicStreamChannel;
23 import io.netty.util.internal.logging.InternalLogger;
24 import io.netty.util.internal.logging.InternalLoggerFactory;
25 import org.jetbrains.annotations.Nullable;
26
27
28
29
30
31 public abstract class Http3RequestStreamInboundHandler extends ChannelInboundHandlerAdapter {
32 private static final InternalLogger logger =
33 InternalLoggerFactory.getInstance(Http3RequestStreamInboundHandler.class);
34
35 @Override
36 public final void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
37 if (msg instanceof Http3UnknownFrame) {
38 channelRead(ctx, (Http3UnknownFrame) msg);
39 } else if (msg instanceof Http3HeadersFrame) {
40 channelRead(ctx, (Http3HeadersFrame) msg);
41 } else if (msg instanceof Http3DataFrame) {
42 channelRead(ctx, (Http3DataFrame) msg);
43 } else {
44 super.channelRead(ctx, msg);
45 }
46 }
47
48 @Override
49 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
50 if (evt == ChannelInputShutdownEvent.INSTANCE) {
51 channelInputClosed(ctx);
52 }
53 ctx.fireUserEventTriggered(evt);
54 }
55
56 @Override
57 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
58 if (cause instanceof QuicException) {
59 handleQuicException(ctx, (QuicException) cause);
60 } else if (cause instanceof Http3Exception) {
61 handleHttp3Exception(ctx, (Http3Exception) cause);
62 } else {
63 ctx.fireExceptionCaught(cause);
64 }
65 }
66
67
68
69
70
71
72
73
74 protected abstract void channelRead(ChannelHandlerContext ctx, Http3HeadersFrame frame) throws Exception;
75
76
77
78
79
80
81
82
83 protected abstract void channelRead(ChannelHandlerContext ctx, Http3DataFrame frame) throws Exception;
84
85
86
87
88
89
90
91 protected abstract void channelInputClosed(ChannelHandlerContext ctx) throws Exception;
92
93
94
95
96
97
98
99
100
101 protected void channelRead(@SuppressWarnings("unused") ChannelHandlerContext ctx, Http3UnknownFrame frame) {
102 frame.release();
103 }
104
105
106
107
108
109
110
111 protected void handleQuicException(@SuppressWarnings("unused") ChannelHandlerContext ctx, QuicException exception) {
112 logger.debug("Caught QuicException on channel {}", ctx.channel(), exception);
113 }
114
115
116
117
118
119
120
121 protected void handleHttp3Exception(@SuppressWarnings("unused") ChannelHandlerContext ctx,
122 Http3Exception exception) {
123 logger.error("Caught Http3Exception on channel {}", ctx.channel(), exception);
124 }
125
126
127
128
129
130
131
132
133 @Nullable
134 protected final QuicStreamChannel controlStream(ChannelHandlerContext ctx) {
135 return Http3.getLocalControlStream(ctx.channel().parent());
136 }
137 }