简体   繁体   English

Netty:单个HTTP请求或响应中的字节数?

[英]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? 在使用Netty编写的HTTP反向代理中,如何确定单个HTTP请求(标头+任何正文内容)或为单个HTTP响应编写的字节数? How can Netty's out of the box HTTPRequestDecoder and HTTPResponseEncoder (or superclasses) be made to make this information available to other ChannelHandler s? Netty的开箱即用HTTPRequestDecoderHTTPResponseEncoder (或超类)如何使这些信息可供其他ChannelHandler

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. 我知道很容易在管道的开头粘贴一个ChannelHandler来记录聚合中为通道写入和读取的字节,但我不希望这样 - 我想知道每个请求和每个读取或写入的字节数响应。 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. 由于Netty开箱即用的HTTP编码器和解码器是进行读写操作的,我希望能够将某些内容子类化并“挂入”读/写逻辑,以便为每个编码或解码的消息获取这些计数。 Is this possible? 这可能吗?

This data is important when representing request/response size histograms as well as supporting HTTP extended access log formats: 在表示请求/响应大小直方图以及支持HTTP扩展访问日志格式时,此数据非常重要:

http://httpd.apache.org/docs/current/mod/mod_log_config.html 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? 一旦完全读取请求或Netty处理程序完全写入响应,我如何确定在输出字符串中替换上述格式标记所需的计数?

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. 目前无法获取这些信息,因为Netty只将HttpRequest / HttpResponse / HttpContent的“已解析”表示传递给管道中的下一个处理程序。 You would need to do the math by yourself by for example count each char in the headers etc. 您需要自己进行数学计算,例如计算标题中的每个字符等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM