2727import io .netty .handler .codec .http .HttpHeaders ;
2828import io .netty .handler .codec .http .HttpResponseStatus ;
2929import io .netty .handler .codec .http .websocketx .WebSocketFrame ;
30+ import io .netty .handler .timeout .IdleStateEvent ;
3031import io .netty .util .Attribute ;
3132
3233import org .jooby .spi .HttpHandler ;
@@ -42,11 +43,18 @@ public class NettyHandler extends SimpleChannelInboundHandler<Object> {
4243
4344 private HttpHandler handler ;
4445
45- private Config config ;
46+ private String tmpdir ;
47+
48+ private int wsMaxMessageSize ;
4649
4750 public NettyHandler (final HttpHandler handler , final Config config ) {
4851 this .handler = requireNonNull (handler , "Application handler is required." );
49- this .config = requireNonNull (config , "Application config is required." );
52+ this .tmpdir = config .getString ("application.tmpdir" );
53+ this .wsMaxMessageSize = Math
54+ .max (
55+ config .getBytes ("server.ws.MaxTextMessageSize" ).intValue (),
56+ config .getBytes ("server.ws.MaxBinaryMessageSize" ).intValue ()
57+ );
5058 }
5159
5260 @ Override
@@ -65,7 +73,7 @@ public void channelRead0(final ChannelHandlerContext ctx, final Object msg) {
6573 boolean keepAlive = HttpHeaders .isKeepAlive (req );
6674
6775 try {
68- NettyRequest nreq = new NettyRequest (ctx , req , config . getString ( "application. tmpdir" ) );
76+ NettyRequest nreq = new NettyRequest (ctx , req , tmpdir , wsMaxMessageSize );
6977 handler .handle (nreq , new NettyResponse (ctx , nreq , keepAlive ));
7078 } catch (Throwable ex ) {
7179 exceptionCaught (ctx , ex );
@@ -90,4 +98,16 @@ public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cau
9098 }
9199 }
92100
101+ @ Override
102+ public void userEventTriggered (final ChannelHandlerContext ctx , final Object evt )
103+ throws Exception {
104+ // Idle timeout
105+ if (evt instanceof IdleStateEvent ) {
106+ log .debug ("idle timeout: {}" , ctx );
107+ ctx .close ();
108+ } else {
109+ super .userEventTriggered (ctx , evt );
110+ }
111+ }
112+
93113}
0 commit comments