File tree Expand file tree Collapse file tree
02nio/nio02/src/main/java/io/github/kimmking/gateway Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package io .github .kimmking .gateway .filter ;
2+
3+ import io .netty .channel .ChannelHandlerContext ;
4+ import io .netty .channel .ChannelInboundHandlerAdapter ;
5+ import io .netty .handler .codec .http .FullHttpRequest ;
6+
7+ public class NettyRequestFilter extends ChannelInboundHandlerAdapter implements HttpRequestFilter {
8+
9+ @ Override
10+ public void filter (FullHttpRequest fullRequest , ChannelHandlerContext ctx ) {
11+ fullRequest .headers ().set ("nio" , "cyy" );
12+ ctx .fireChannelRead (fullRequest );
13+ }
14+
15+ @ Override
16+ public void channelRead (ChannelHandlerContext ctx , Object msg ) throws Exception {
17+ FullHttpRequest fullRequest = (FullHttpRequest ) msg ;
18+ this .filter (fullRequest , ctx );
19+ }
20+ }
Original file line number Diff line number Diff line change 11package io .github .kimmking .gateway .inbound ;
22
3+ import io .github .kimmking .gateway .filter .NettyRequestFilter ;
34import io .netty .channel .ChannelInitializer ;
45import io .netty .channel .ChannelPipeline ;
56import io .netty .channel .socket .SocketChannel ;
@@ -23,6 +24,7 @@ public void initChannel(SocketChannel ch) {
2324 p .addLast (new HttpServerCodec ());
2425 //p.addLast(new HttpServerExpectContinueHandler());
2526 p .addLast (new HttpObjectAggregator (1024 * 1024 ));
27+ p .addLast (new NettyRequestFilter ());
2628 p .addLast (new HttpInboundHandler (this .proxyServer ));
2729 }
2830}
You can’t perform that action at this time.
0 commit comments