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:

  1. httprequestdecoder
  2. mycookiehandler
  3. 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:

  1. httprequestdecoder
  2. httpresponseencoder
  3. mycookiehandler
  4. myrequesthandler

and works.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -