Forum Discussion
iRule for Response Header "content-length"
I need help with getting the "content-length" value in Response header. Basically the iRule should check for HTTP "Status" 404 and "content-length" not equal to zero.
Thanks in advance,
- hoolio
Cirrostratus
You can get the Content-Length header value using 'HTTP::header value "Content-Length"'. Note that if the server responds with chunked encoding there wouldn't be a Content-Length header and [HTTP::header value "Content-Length"] would return a null length string.when HTTP_RESPONSE { Check if response code is a 404 and the Content-Length header value is 0 if {[HTTP::status] == 404 && [HTTP::header value "Content-Length"] == 0}{ Do something? log local0. "[IP::client_addr]:[TCP::client_port]: Found 404 response with 0 Content-Length" } }
- Vishal_96707
Nimbostratus
Thanks. I am stucked in weird issue. It is for sharepoint 2007 environment. We are migrating from sharepoint 2003 to sharepoint 2007. We have configured an iRule which redirect 404 and file not found requests to the migrated site. The problem is when sharepoint is accessed via UNC. As standard functionality windows check for files like thumbs.db, file/folder present etc. which returns "404" code. This is where the UNC access stops working. Actually the file like thumbs.db etc. are not present on the sharepoint server. We would not like to have a rule which will not redirect if the return code is 404 and "content-length" is not equal to zero. - Vishal_96707
Nimbostratus
How do I work on the Integer values? I want check a condition where the "content-value" will not be equal to zero. - Colin_Walker_12Historic F5 AccountYou mean the content-length? If you just want to check the content-length header, then you'd do this:
if {!([HTTP::header "content-length"] = 0) } { do something here... }
- Deb_Allen_18Historic F5 AccountKeep in mind that 404's may (typically do) include a message body containing explanatory text, which would mean content length may not be 0 for a 404. From RFC2616:All 1xx (informational), 204 (no content), and 304 (not modified) responses MUST NOT include a message-body. All other responses do include a message-body, although it MAY be of zero length.Also, if it does contain a message body, it may be sent in a chunked response, which would mean there is no Content-Length header at all.
- Vishal_96707
Nimbostratus
Can you guys help me with troubleshooting. The first part didnt work as expected. I am not getting any response code when i try to go to non-existent sharepoint site.when HTTP_RESPONSE { Check if response code is a 404 and the Content-Length header value is 0 if {([HTTP::status] == 404) && !([HTTP::header value "Content-Length"] == 0)}{ log local0. "[IP::client_addr]:[TCP::client_port]: Found 404 response with Content-Length as [HTTP::header value "Content-Length"]" HTTP::redirect "https://intranet.mydomain.com/_layouts/redirects/Default.aspx?URL=$MYHOST$MYURL" } }
- Deb_Allen_18Historic F5 AccountIt's very difficult to debug iRule logic without seeing the traffic it is intended to affect. Your best bet would be to capture and examine a trace of the request & response you are trying to manipulate (HTTPwatch/LiveHeaders/tcpdump/Wireshark etc), then use the actual combinations of events as seen in the trace to condition your iRule.
- Vishal_96707
Nimbostratus
Thank you all for your help. I manage to resolve the issue. I used fiddler and iRule logging for troubleshooting :-), Thanks again. - Rise_77519
Nimbostratus
Hi, I am using the irule to direct the users to the test1 pool when they send the test_string in soap data . But I also want to direct the users to test2 pool when they no any soap data sent by xml post request. My irule is the below but i am getting the "err tmm1[17512]: 01220001:3: TCL error: /Common/xml_rule - Illegal argument (line 2) invoked from within "HTTP::collect [HTTP::header Content-Length]" " error message in /var/log/ltm when no any soap data was sent. how can i regulate my irule? thanks,
when HTTP_REQUEST { HTTP::collect [HTTP::header Content-Length] } when HTTP_REQUEST_DATA { if {[findstr [HTTP::payload] "list" 1 " x" ] contains "test_string" }{
pool test1 } if {!([HTTP::header "content-length"] = 0) } { pool test2 }
HTTP::release }
- nitass
Employee
"err tmm1[17512]: 01220001:3: TCL error: /Common/xml_rule - Illegal argument (line 2) invoked from within "HTTP::collect [HTTP::header Content-Length]" " error message in /var/log/ltm when no any soap data was sent.
does content-length header exist (i.e. [HTTP::header content-length] is not null)?
what about something like this?
when HTTP_REQUEST { if { [HTTP::header exists Content-Length] } { HTTP::collect [HTTP::header Content-Length] } else { do something } } when HTTP_REQUEST_DATA { if { [findstr [HTTP::payload] "list" 1 " x" ] contains "test_string" } { pool test1 } else { pool test2 } }
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