Forum Discussion

6 Replies

  • I don't think you can set the method with HTTP::method. The wiki page only shows that you can retrieve the method--not set it. If you could change the request method, I'm not sure it would be a good idea. You'd have to try to handle any POST data that was sent with the request.

    If you send a redirect to the same host and URI, the client should follow the redirect with a GET:

    
    when HTTP_REQUEST {
       if {$some_condition == 1}{
          HTTP::redirect http://[HTTP::host][HTTP::uri]
       }
    }

    Aaron
  • Patrick_Chang_7's avatar
    Patrick_Chang_7
    Historic F5 Account
    You can do it, but you would have to manually recreate the request in its entirety. This would require parsing the post data and converting them into query parameters in the URI. There is a secret function (not well documented) in the F5 Web Accelerator which will do this for you automatically.
  • Interesting, but we do not have the Web Accelerator license.

     

     

    Do you pchang or anyone else have an example on how to build/recreate the request from the start inside iRules?

     

     

    One thing is to create the header values and the uri which is easy to change with HTTP::uri and HTTP::header, but how to specify to use GET or POST?

     

     

    Another thing.

     

     

    If I receive a POST and wants to resend it with HTTP::retry. How can that be done?

     

     

    This code

     

    
    when HTTP_REQUEST {
    set orginal_request [HTTP::request]
    }
    when HTTP_RESPOND {
         if {some condition} {
             HTTP::retry $orginal_request
         }
    }

     

    Will only resend the request and not the POST data. If I do a collect, I will receive the POST data, but how can the payload be resent?
  • I don't think there is a way to change the method using HTTP:: commands. I suppose you could collect the TCP data and replace the POST string with GET within the TCP payload. I don't think it would be a simple thing to do though.

     

     

    I'm wondering if it wouldn't be much easier to rewrite the response from the web app that generates the request you want to change from a POST to a GET. If you knew the URI and/or form name which generates the POST request, you could use a stream command to rewrite the form method from POST to GET. This would also eliminate the need to convert POST parameters to the URI.

     

     

    Aaron
  • I would think you could modify the variable you're saving the request to, $orginal_request, before using HTTP::retry $orginal_request.

     

     

    Aaron
  • I found the solution now on how to do a HTTP::retry if the request method is POST

    
    when HTTP_REQUEST {
    set orginal_request [HTTP::request]
    HTTP::collect [HTTP::header "Content-Length"]
    if {$isRetry} {
    HTTP::header replace Content-Length "0"
    HTTP::payload replace 0 0 $payloadReq
    set isRetry 0
    }
    }
    when HTTP_REQUEST_DATA {
    set payloadReq [HTTP::payload]
    }
    when HTTP_RESPOND {
         if {some condition} {
    HTTP::retry $orginal_request
    set isRetry 1
         }
    }