Forum Discussion
Conor_Cunningha
Nimbostratus
Oct 07, 2008Replace Host on Original HTTP Request
Hi All,
I'm looking to do the following;
In the HTTP_Request, store the entire request in a variable called orgRequest
If I get a 302 redirect in the response I want to change the header "Host" to the IP address I received in the redirect.
I have a variable called newHost which has the IP address and port of where I want to go, what I don't know how to do is to replace the "Host" in the original request and resend. What I am currently seeing is that my output in /var/log/ltm shows my orgRequest with the original "Host" header.
Ideally I could do this by invoking the LB_Selected Event, but I don't know if you can invoke events - does anyone know if this is possible?
Basically what I have looks like this (semi-pseudo code)
HTTP_Request {
set orgRequest [HTTP::request]
}
HTTP_Response {
if 302 redirect
set newHost = Location Header of 302 response
set orgRequest $orgRequest[HTTP::header replace "Host" "$newHost"]
HTTP::retry $orgRequest
}
Cheers,
Conor
- hoolio
Cirrostratus
Hi Conor,set orgRequest [string map {oldhost.example.com newhost.example.com} [HTTP::request]]
when CLIENT_ACCEPTED { Track whether we're retrying the request set retrying 0 } when HTTP_REQUEST { Check if some condition is true, where we want to potentially retry the request if {$some_condition}{ Check if this is a retried request if {$retry}{ Update the Host header value HTTP::header replace Host "newhost.example.com" Specify a new destination for this request node $new_ip $new_port } else { set orgRequest [HTTP::request] } } } when HTTP_RESPONSE { Add logic for when to retry the request and set retry to 0 or 1 }
- Conor_Cunningha
Nimbostratus
Aaron, - hoolio
Cirrostratus
If you use string map, you could make the match more specific by including the "Host:" portion:
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