Forum Discussion

hu_127869's avatar
hu_127869
Historic F5 Account
Dec 16, 2005

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 !
  • bl0ndie_127134's avatar
    bl0ndie_127134
    Historic F5 Account
    Hmm 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_127869's avatar
    hu_127869
    Historic F5 Account
    Thanks for your help. However ,the bad thing is that server do not write the content-length information in the header .
  • hu_127869's avatar
    hu_127869
    Historic F5 Account
    I 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_127134's avatar
    bl0ndie_127134
    Historic F5 Account
    How 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_127134's avatar
    bl0ndie_127134
    Historic F5 Account
    Note that I have the response codes logic reversed but it should still demonstrate the point.
  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    You shouldn't need the "TCP::collect 100" in the SERVER_DATA event.

     

    That might be causing the error you are seeing.