Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netty: number of bytes in a single HTTP request or response?

In an HTTP reverse proxy written with Netty, how do you determine the number of bytes read for a single HTTP request (headers + any body content) or written for a single HTTP response? How can Netty's out of the box HTTPRequestDecoder and HTTPResponseEncoder (or superclasses) be made to make this information available to other ChannelHandlers?

I know it is easy to stick a ChannelHandler at the beginning of the pipeline to record bytes written and read for the channel in aggregate, but I don't want that - I want to know the number of bytes read or written per request and per response. Since Netty's out of the box HTTP encoder and decoder are the ones doing the reading and writing, my hope is that I can subclass something and 'hook in' to the read/writing logic to get those counts per message encoded or decoded. Is this possible?

This data is important when representing request/response size histograms as well as supporting HTTP extended access log formats:

http://httpd.apache.org/docs/current/mod/mod_log_config.html

From that page, access log format string tokens used when logging a single request/response pair:

%I  Bytes received, including request and headers. Cannot be zero. You need to enable mod_logio to use this.
%O  Bytes sent, including headers. May be zero in rare cases such as when a request is aborted before a response is sent. You need to enable mod_logio to use this.
%S  Bytes transferred (received and sent), including request and headers, cannot be zero. This is the combination of %I and %O. You need to enable mod_logio to use this.

Once a request is completely read or response is completely written by the Netty handlers, how would I determine the counts necessary to substitute the above format tokens in an output string?

like image 314
Les Hazlewood Avatar asked Nov 08 '22 11:11

Les Hazlewood


1 Answers

There is currently no way to get these informations as Netty only pass on the "parsed" representation of the HttpRequest/HttpResponse/HttpContent to the next handlers in the pipeline. You would need to do the math by yourself by for example count each char in the headers etc.

like image 161
Norman Maurer Avatar answered Nov 14 '22 21:11

Norman Maurer