Re: determine size of http headers

2014-01-27 Thread Willy Tarreau
On Thu, Jan 23, 2014 at 01:19:40PM -0500, Patrick Hemmer wrote:
 What I'd like to do is add a few items to the log line which contain the
 size of the headers, and then the value of the Content-Length header.
 This way if the connection is broken for any reason, we can determine if
 the client sent all the data they were supposed to.
 
 Logging the Content-Length header is easy, but I can't find a way to get
 the size of the headers.
 The only way that pops into mind is to look for the first occurrence of
 \r\n\r\n and get its offset (and preferably add 4 as to include the size
 of the \r\n\r\n in the calculation). But I don't see a way to accomplish
 this.
 
 Any ideas?

Haproxy knows this value when switching to the body analyzer.
In http_wait_for_response, after the if (msg_state  MSG_BODY),
you're guaranteed that msg-eoh contains the exact number of bytes
of headers. In fact it points to the CRLF that marks the last
header, where new headers will be added if needed.

I have no immediate good idea on how to put that into logs, but at
least you know where to look for it :-)

Be careful, this part is reused by the chunk parser, so you need to
log it or to copy it before it's reused. If you use the logasap option,
it should remain untouched though. 

Willy




determine size of http headers

2014-01-23 Thread Patrick Hemmer
What I'd like to do is add a few items to the log line which contain the
size of the headers, and then the value of the Content-Length header.
This way if the connection is broken for any reason, we can determine if
the client sent all the data they were supposed to.

Logging the Content-Length header is easy, but I can't find a way to get
the size of the headers.
The only way that pops into mind is to look for the first occurrence of
\r\n\r\n and get its offset (and preferably add 4 as to include the size
of the \r\n\r\n in the calculation). But I don't see a way to accomplish
this.

Any ideas?

Thanks

-Patrick