cancel
Showing results for 
Search instead for 
Did you mean: 

iRule for Response Header "content-length"

Vishal_96707
Nimbostratus
Nimbostratus

 

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,
15 REPLIES 15

hoolio
Cirrostratus
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" } }

 

 

Aaron

Vishal_96707
Nimbostratus
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.

 

 

I will try your suggestions.

Vishal_96707
Nimbostratus
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_12
Historic F5 Account
You 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... }

 

 

This says "If the content length is not equal to zero, do something". Is that what you're looking for? This is almost identical to what hoolio posted above, except this includes the "not" operation.

 

 

Colin

Deb_Allen_18
Historic F5 Account
Keep 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.

 

 

HTH

 

/d

 

Vishal_96707
Nimbostratus
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" } }

 

 

I want the user requests using Web Cliet or WebDav services and calling sharepoint using UNC to not redirect for checks like Desktop.ini, file existence check for owerwrite, thumbs.db etc.

 

 

Thanks in advance.

Deb_Allen_18
Historic F5 Account
It'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
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
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
F5 Employee
F5 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 } }

Waseem_Shaik_97
Nimbostratus
Nimbostratus

Hello All ,

 

I have a customer , who is request to insert content length by F5 (10.2.4) for all the server response , since he cannot do at the server side. How the irule looks like for this request since based on above thread I cannot find the right irule.

 

Any help is really appreciated.

 

Waseem

 

Waseem_Shaik_97
Nimbostratus
Nimbostratus

Hello All ,

 

I have a customer , who is request to insert content length by F5 (10.2.4) for all the server response , since he cannot do at the server side. How the irule looks like for this request since based on above thread I cannot find the right irule.

 

Any help is really appreciated.

 

Waseem

 

nitass
F5 Employee
F5 Employee

How the irule looks like for this request since based on above thread I cannot find the right irule.

 

e.g.

 

Insert Content Into Server Response

 

https://devcentral.f5.com/wiki/iRules.InsertContentIntoServerResponse.ashx

 

Javascript Insert v10+ by Bhattman, Russell McGinnis

 

https://devcentral.f5.com/wiki/iRules.WebPage_Script_Insert_v10.ashx

 

insert javascript to html pages using irules

 

https://devcentral.f5.com/questions/insert-javascript-to-html-pages-using-irules

 

Waseem_Shaik_97
Nimbostratus
Nimbostratus

So in the above first link , I see this irule

 

when HTTP_RESPONSE { Insert HTML comment to the top of the payload. HTTP::payload replace 0 0 "" }

 

can we put any text or variable or leave this portion empty "

 

nitass
F5 Employee
F5 Employee

can we put any text or variable or leave this portion empty "

 

it should not be empty. it is portion that is going to be inserted in the response (on top).