Forum Discussion

Root44's avatar
Root44
Icon for Altostratus rankAltostratus
Sep 19, 2017

f5 LB iRule Redirection for POST method

Hello guys,

I need some help here. There user is hitting the url which has a VIP1 on LB1 and from there it is getting redirected to VIP2 on LB2 using an iRule. When I used 307 redirection, it didn't work for POST method as it was coming from some SOAP UI tool (Worked for GET). Am I missing something here? Trying to check if I need to modify my rule.

when HTTP_REQUEST {
    set uri "[HTTP::uri]"switch -glob [HTTP::uri] {
        "/some_uri/*" {
            if { [string tolower [HTTP::method]] eq "POST" } {
                HTTP::respond 307 Location "https://test.example.com" }
        }
        default { pool some_pool }
    }
} 

Please help.

Thanks, R

4 Replies

  • Why do you use a 307 redirect?? Isn't a 301 or 302 redirect a better option?

     

    Cheers,

     

    Kees

     

  • In RFC 7231:

     

    6.4.7. 307 Temporary Redirect

     

    The 307 (Temporary Redirect) status code indicates that the target resource resides temporarily under a different URI and the user agent MUST NOT change the request method if it performs an automatic redirection to that URI. Since the redirection can change over time, the client ought to continue using the original effective request URI for future requests.

     

    The server SHOULD generate a Location header field in the response containing a URI reference for the different URI. The user agent MAY use the Location field value for automatic redirection. The server's response payload usually contains a short hypertext note with a hyperlink to the different URI(s).

     

      Note: This status code is similar to 302 (Found), except that it
      does not allow changing the request method from POST to GET.  This
      specification defines no equivalent counterpart for 301 (Moved
      Permanently) ([RFC7238], however, defines the status code 308
      (Permanent Redirect) for this purpose).

    So the 307 may be the right code to return.

     

    Look at soapui tool support of 307 redirect.

     

    In your code, line 2 may be splitted before switch command. I guess this is a formatting issue when you post the code!

     

  • Hello All,

     

    The issue is resolved after adding the SNI and sending the traffic to the dedicated VIP.

     

  • I know this is an old post. But FYI-- in the question above, tolower is used on the left, but compared to capitalized POST on the right. Change POST to lowecase post if you use something like this...

    if { [string tolower [HTTP::method]] eq "post" } {