Forum Discussion
iRule to drop HTTP GET requests that don't have zero content length header
I'm new to iRules, and hoping to get some assistance. I've searched here for examples and haven't come across anything. I'm looking to implement an iRule that would only allow GET requests that have a content header length = 0, and drop the rest. Any of you expert coders know what that rule would look like? Thanks in advance. Scott
9 Replies
- Kevin_Stewart
Employee
Are you looking for requests that have any content length (like a POST):
when HTTP_REQUEST { if { [HTTP::header exists Content-Length] } { drop } }Or something that specifically has a content length of zero:
when HTTP_REQUEST { if { ( [HTTP::header exists Content-Length] ) and ( [HTTP::header Content-Length] == 0 ) } { drop } } - scott_126211
Nimbostratus
I'm looking to drop only GET requests that don't have 0 content-length. If the GET request is properly formatted with a zero content-length, I want to allow it.
- Kevin_Stewart
Employee
when HTTP_REQUEST { if { ( [HTTP::method] equals "GET" ) and ( [HTTP::header exists Content-Length] ) and ( [HTTP::header Content-Length] == 0 ) } { do nothing } else { reject } }What if the request doesn't have a Content-Length header?
- scott_126211
Nimbostratus
That's a good question....is "not exist" a valid qualifier? so...would this work?
when HTTP_REQUEST { if { ( [HTTP::method] equals "GET" ) and ((( [HTTP::header exists Content-Length] ) and ( [HTTP::header Content-Length] == 0 )) or ( [HTTP::header not exist Content-Length] )) } { do nothing } else { reject } }
- Kevin_Stewart
Employee
Well, it would be:
if { not ( [HTTP::header exists Content-Length] ) } { ... } - scott_126211
Nimbostratus
Thanks Kevin!!!
So does this look like the right way to implement it?
when HTTP_REQUEST { if { ( [HTTP::method] equals "GET" ) and ( [HTTP::header exists Content-Length] ) and ( [HTTP::header Content-Length] == 0 ) } or { not ( [HTTP::header exists Content-Length] ) } do nothing } else { reject } }
- Kevin_Stewart
Employee
Do you want to allow or deny if the Content-Length header DOES NOT exist? - scott_126211
Nimbostratus
allow.
- Kevin_Stewart
Employee
I think this will work... 😉
when HTTP_REQUEST { if { ( [HTTP::method] equals "GET" ) and ( ( ( [HTTP::header exists Content-Length] ) and ( [HTTP::header Content-Length] == 0 ) ) or ( not [HTTP:::header exists Content-Length] ) ) } { do nothing } else { reject } }
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