i have an issue where i have not yet been able to find a working solution to. Maybe someone came across the same and knows a way on how to solve it with an irule.
problem:
we have an http client that does not send the Content-Length header parameter in its http POST requests. This in turn creates issues on the receiving server. I thought it would be nice if i could simply calculate the Content-Length in an irule and then add it to the request with “HTTP::header insert “Content-Length” $clength”. Now the issue is that i have not managed to come fill the clength variable with a value…
I played with HTTP::collect and HTTP::payload but i have not managed to get a working result.
did anyone already have a similar issue and maybe also have a working irule to solve this?
I assume the client is trying to terminate the HTTP request by closing the TCP connection as it doesn’t include a Content-Length header and doesn’t set a Transfer-Encoding method of Chunked. An F5 developer should probably be able to provide a more informed suggestion, but in the meantime, you might be able to collect the TCP payload, count the number of bytes in the HTTP headers, calculate the HTTP payload size and then insert an HTTP Content-Length header. I can’t see this being very efficient though.
Is there any chance of changing the client application to explicitly set a content-length header?
i’ve run into a very similar issue - our cdn will not cache content without a content-length header. this is an issue with dynamically-generated content, but many of our tomcat apps will not include the header even if it’s a static page.
to my knowledge the best way to do this is to unchunk first, collect payload, add header, then send it on it’s way. it seems like unchunking and converting to http 1.0 would be a performance hit on large files but i haven’t tested it yet.
nambrosch, your case is slightly different than Marc’s in that you’re concerned about responses without a content-length header where Marc is having an issue with requests without a content-length header. The HTTP profile option for chunking is only used for responses, so I don’t think that will help for Marc.
I think you’d need to search for the first instance of two \r\n (carriage return + line feed, carriage return + line feed) as that is what should delineate the HTTP headers from the payload. I’m not sure if you could use something like ‘string first \r\n\r\n [TCP::payload]’ or whether you’d need to convert the payload to hex first using ‘binary scan [TCP::payload] H* payload_hex (Click here)’ and then search for the CR LF CR LF characters using ‘string first $payload_hex \x0d\x0a\x0d\x0a’.
And unfortunately, I’m not sure if there is a more efficient way to do this. This approach would mean you’d be collecting every TCP payload in order to work around the issue for one client.