help required chaining httphandler and proxyhandler

Trustin Lee (이희승) trustin at gmail.com
Thu Sep 24 20:18:15 EDT 2009


Hello Ron,

Glad that you figured out the solution finally.  I am perhaps too late!

Just one question.  As far as I know, (request.getContentLength() ==
request.getContent().writerIndex()) is always true.  Out of curiosity,
have you ever encountered the case where the condition is false?

— Trustin Lee, http://gleamynode.net/



On Fri, Sep 25, 2009 at 3:18 AM, rzo <rzo at gmx.de> wrote:
> hello,
>
> I got this working.
> for those interested here the changes:
>
> stophandler:
>
>             public void messageReceived(ChannelHandlerContext ctx,
> MessageEvent evt) {
>                 if (evt.getMessage() != null)
>                 {
>                     HttpRequest request = (HttpRequest) evt.getMessage();
> -->                     if (request.getContentLength() == 0 ||
> request.getContentLength() == request.getContent().writerIndex())
>                     {
>                     ChannelBuffer buf = (ChannelBuffer)
> ctx.getPipeline().getContext("interceptStart").getAttachment();
>                      if (buf == null)
>                     {
>                         System.out.println("no buff found");
>                     }
>                     else if (buf.writerIndex() != 0)
>                     {
> -->
> ctx.getPipeline().getContext("interceptStart").setAttachment(null);
>                         ctx.sendUpstream(new
> UpstreamMessageEvent(evt.getChannel(), buf, evt.getRemoteAddress()));
>                     }
>                     }
>
>                 }
>                }
>
> - Ron
>
>
> rzorzorzo wrote:
>> hello,
>>
>> i am trying to implement a proxy which checks the http requests before
>> forwarding these to another server.
>> i tried implementing this with the following pipeline
>>
>> starthandler -> HttpRequestDecoder-> stophandler ->
>> HexDumpProxyInboundHandler
>>
>> starthandler:
>>
>> remembers the incoming bytes in a dynamic buffer until the httprequest has
>> been completely parsed
>>
>>    @Override
>>        public void messageReceived(ChannelHandlerContext ctx, MessageEvent evt)
>> throws Exception
>>        {
>>                ChannelBuffer m = (ChannelBuffer) evt.getMessage();
>>                ChannelBuffer buf = (ChannelBuffer) ctx.getAttachment();
>>                if (buf == null)
>>                {
>>                        buf = dynamicBuffer();
>>                        ctx.setAttachment(buf);
>>                }
>>                m.markReaderIndex();
>>                buf.writeBytes(m);
>>                m.resetReaderIndex();
>>            super.messageReceived(ctx, evt);
>>           }
>>
>> stophandler
>>
>>
>>                   @Override
>>                        public void messageReceived(ChannelHandlerContext ctx, MessageEvent evt)
>> {
>>                                if (isOk((HttpRequest)evt.getMessage()))
>>                                {
>>                                        ChannelBuffer buf = (ChannelBuffer)
>> ctx.getPipeline().getContext("interceptStart").getAttachment();
>>                                       ctx.sendUpstream(new UpstreamMessageEvent(evt.getChannel(), buf,
>> evt.getRemoteAddress()));
>>
>>                                }
>>                           }
>>
>> both extend simple channel upstream handler and
>> @ChannelPipelineCoverage("one")
>>
>> for the first page this seems to work well, but for subsequent http requests
>> not.
>>
>> any hints or help or other ideas how to implement this with netty ?
>>
>> - Ron
>>
>>
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>



More information about the netty-users mailing list