Forum Discussion

OSAMUchan_32647's avatar
OSAMUchan_32647
Icon for Nimbostratus rankNimbostratus
Aug 22, 2017

I have a question about the notation of iRules (HTTP_RESPONSE)

Always thank you for your help. I have a question about the notation of iRules.

 

There is iRules with HTTP_RESPONSE as below.

 

when HTTP_RESPONSE { if {[HTTP::status] matches_glob {[4][0][1-9]} } { HTTP::redirect "; } if {[HTTP::status] matches_glob {[4][1-9][0-9]} } { HTTP::redirect "; } if {[HTTP::status] matches_glob {[5][0-9][0-9]} } { HTTP::redirect "; } }

 

If left unchanged, all errors will be redirected, but it will be redirected even during application development, which will hinder development work.

 

When "X - AAA - BBB - RESPONSE" is included in the HTTP header, we do not want to redirect but we want to return error to the terminal which accessed as it is.

 

It would be greatly appreciated if you could tell me how to write iRules in this case in Japanese.

 

1 Reply

  • Hi,

    During application development, you can use this irule :

     

    when CLIENT_ACCEPTED {
        set nodebug 1
    }
    
    when HTTP_REQUEST {
        if {([HTTP::cookie value debug_mode] equals 1) || ([URI::query [HTTP::uri] debug_mode] equals 1)} {
            set nodebug 0
        } 
    }
    
    when HTTP_RESPONSE {
        if {$nodebug} {
            switch -glob -- [HTTP::status] {
                [4][0][1-9] -
                [4][1-9][0-9] {
                    HTTP::redirect "https://naiyo.com/err/notfound.html";
                }
                [5][0-9][0-9] {
                    HTTP::redirect "https://naiyo.com/err/servererror.html";
                }
            }
        } else {
            HTTP::cookie insert name debug_mode value 1
        }
    }
    

     

    the goal of this code is to use query parameter debug_mode=1 first time to allow debug mode.

    then, a cookie is inserted in the response and next requests will be managed as debug.