Forum Discussion
hu_127869
Dec 16, 2005Historic F5 Account
How to rewrite the status from 205 to 200
Hi :
I would like to rewrite http status code 205 to 200. I try to use http:respond 200 , However, the payload is erased , Any good sample for me to rewrite the status code and also keep my original content/header. Thanks !
6 Replies
- bl0ndie_127134Historic F5 AccountHmm good question! Unfortunately for some reason our HTTP developer did not provide any way to change the response code, but that does not mean you can’t do it. There are a couple of approaches to this problem.
If you know ahead of time that you will be getting a 205 request (special request method, request cookie etc) then you can do a TCP::collect on the server side and replace the response code using TCP::payload replace.
If if you don’t have the priveledge of knowing this ahead of time, you will need to write some thing like this ...when HTTP_RESPONSE { if {[HTTP::status] == 205}{ HTTP::collect [HTTP::header Content-Length] } } when HTTP_RESPONSE_DATA { HTTP::respond 200 content [HTTP::payload] }
The first approach while a little bit more difficult, can be more superior because you will not be buffering unnecessary payload. But if the 205 response payload size is not very large then I would go with the second one. - hu_127869Historic F5 AccountThanks for your help. However ,the bad thing is that server do not write the content-length information in the header .
- hu_127869Historic F5 AccountI have a rule like this , It works sometimes , however, sometime do not , And got an error in /var/log/ltm like this
--- http_process_state_prepend - Invalid action EV_INGRESS_DATA during ST_HTTP_PREPEND_HEADERS --------------
rule httpcodechange {
when SERVER_CONNECTED {
TCP::collect
}
when SERVER_DATA {
TCP::collect 100
set httpcodeheader [findstr [TCP::payload] "HTTP/1.0" 9 "\r"]
if { $httpcodeheader eq "205 Reset Content" } {
log local0. "error=($httpcodeheader)"
TCP::payload replace 9 17 "200 OK"
}
TCP::release
}
} - bl0ndie_127134Historic F5 AccountHow about some thing like this. It appears to work for me.
when HTTP_REQUEST_SEND { TCP::collect 12 } when SERVER_DATA { if {[findstr [TCP::payload 12] "200"] == "200"} { TCP::payload replace 9 3 "205" } } - bl0ndie_127134Historic F5 AccountNote that I have the response codes logic reversed but it should still demonstrate the point.
- unRuleY_95363Historic F5 AccountYou shouldn't need the "TCP::collect 100" in the SERVER_DATA event.
That might be causing the error you are seeing.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
