netty - Interrupting an HTTP session with a forbidden error -
in netty server application receive httprequest must processed if cookie particular content present , valid (a kind of authentication). in pipeline have following objects:
- httprequestdecoder
- mycookiehandler
- myrequesthandler
what want that, if cookie not present or not valid, no further elaboration occurs , forbidden error returned.
this i've done inside 'mycookiehandler' :
public void channelread(channelhandlercontext ctx, object msg) throws exception { ... if (!isvalid(cookie)) { ctx.writeandflush( new defaultfullhttpresponse(http_1_1, forbidden)) .addlistener(channelfuturelistener.close); return; } }
however, 'writeandflush' called client receives error 'empty reply server'.
what's wrong in code?
thanks, massimiliano
i found error. adding future listener channelfuture
returned writeandflush
, discovered problem httpresponseencoder
needed pipeline encode answer bytebuf
.
so, solve problem, change pipeline way:
- httprequestdecoder
- httpresponseencoder
- mycookiehandler
- myrequesthandler
and works.
Comments
Post a Comment