Forum Discussion
DNSgeek_90802
Nimbostratus
Dec 28, 2009Get HTTP::uri in HTTP_RESPONSE
I have an irule that needs to get the URI from a 404 page and muck with it. However, when I try to reference [HTTP::uri], I get told that I cannot access it from the HTTP_RESPONSE context.
...
hoolio
Cirrostratus
Dec 28, 2009Ah, so that error is because the HTTP::path command is not valid in the HTTP_RESPONSE event. There isn't a URI or path in responses.
If you want to retry the request to a new pool, you can use HTTP::retry. Here is a rough, untested example.
I'm assuming you are only concerned with GET requests. If you want to handle POSTs or other requests with a payload, you'd need to collect the payload on every request using HTTP::collect and then append the payload to the request headers in HTTP_REQUEST_DATA.
Based on the example on the HTTP::request wiki page:
http://devcentral.f5.com/wiki/default.aspx/iRules/http__retry.html
when CLIENT_ACCEPTED {
Initialize a variable to track whether a request has been retried
set retries 0
}
when HTTP_REQUEST {
Check if request is a GET (we only save the request headers using HTTP::request)
if {[HTTP::method] eq "GET"}{
Save the request headers
set request_headers [HTTP::request]
log local0. "HTTP request headers: $request_headers"
}
}
when LB_SELECTED {
if { $retries >= 1 } {
LB::reselect pool pool_b
}
}
when HTTP_RESPONSE {
if { [HTTP::status] == 404 } {
incr retries
log local0. "4xx error caught: retry $retries out of [active_members [LB::server pool]]"
if { $retries < [active_members [LB::server pool]] } {
HTTP::retry $request_headers
}
} else {
Successful response, reset the retries variable
set retries 0
}
}
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects