Forum Discussion
HTTP::Response with Chunking
I’m trying to use an I-Rule to mimic an application response. It may be failing due to chunking. The message I want to mimic has something like this in it
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/xml;charset=utf-8 Transfer-Encoding: chunked Date: Thu, 26 Jun 2014 17:40:25 GMT … followed by a SOAP message
My I-Rule finds messages where this is an appropriate response, then uses HTTP::respond to send stuff to the client that looks more like the first message. It looks something like this:
HTTP::respond 200 content "" Content-Type "text/xml;charset=utf-8" Date "Thu, 26 Jun 2014 17:40:25 GMT"
Unlike the real message, the I-Rule generated message does not do chunking. Is there a way to make sure the Response is chunked? If I add ‘ Transfer-Encoding "chunked" ‘ to the end of the HTTP:respond line, it just hangs the I-Rule. Thanks,
Jeff
2 Replies
- Kevin_Stewart
Employee
A few things to consider:
-
The HTTP::respond command automatically calculates and inserts a Content-Length header, which is not allowed when a Transfer-Encoding header exists. To get around that, use the TCP::respond command instead and write the entire payload manually.
-
You may also notice in the Apache response that the first line of the content is either a number or a hexadecimal value. This "prefix" is generally required for Transfer-Encoding. It tells the browser how much data to expect in each response.
So given the above, you could do something like this:
when HTTP_REQUEST { TCP::respond "HTTP/1.1 200 OK\r\nContent-Type: text/xml;charset=utf-8\r\nTransfer-Encoding: chunked\r\n\r\n129\r\nGambardella, MatthewXML Developer's GuideComputer44.952000-10-01An in-depth look at creating applications with XML.\r\n0\r\n\r\n" }Notice the 129 as the start of the payload. This is the hexadecimal encoding of the content length (in this case 297 without the escape "\" characters). If this is the end of the data, then it's followed by a 0 chunk (\r\n0\r\n\r\n).
-
- Kevin_Stewart
Employee
Do you have to do all of this in the HTTP_REQUEST_DATA event? Are you looking for something in the request payload?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com