File tree Expand file tree Collapse file tree
02nio/nio02/src/main/java/io/github/kimmking/gateway/filter Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import io .netty .channel .ChannelHandlerContext ;
44import io .netty .handler .codec .http .FullHttpRequest ;
5+ import io .netty .handler .codec .http .HttpRequest ;
6+
7+ import java .net .InetSocketAddress ;
58
69public class HeaderHttpRequestFilter implements HttpRequestFilter {
710
811 @ Override
912 public void filter (FullHttpRequest fullRequest , ChannelHandlerContext ctx ) {
13+ String uri = fullRequest .uri ();
14+ String ip = HeaderHttpRequestFilter .getIpAddr (ctx );
15+ System .out .println ("ip=" +ip +"/uri=" +uri );
1016 fullRequest .headers ().set ("mao" , "soul" );
1117 }
18+ public static String getIpAddr (ChannelHandlerContext ctx ) {
19+ String ip = "" ;
20+ try {
21+ InetSocketAddress insocket = (InetSocketAddress ) ctx .channel ().remoteAddress ();
22+ ip = insocket .getAddress ().getHostAddress ();
23+ System .out .println (ip );
24+ }catch (Exception e ) {
25+ e .printStackTrace ();
26+ }
27+
28+ return ip ;
29+ }
30+
1231}
You can’t perform that action at this time.
0 commit comments