Forum Discussion

Thiyagu's avatar
Thiyagu
Icon for Cirrus rankCirrus
May 22, 2024

Need help with an iRule for HTTP Methods

Could you please review the below iRule and suggest?

when HTTP_REQUEST {
  if { ( [HTTP::method] equals "PUT" ) } {
    switch -glob [string tolower [HTTP::uri]] {
      "/rws/api/v1/devices/*" -
      "/rws/api/v1/accounts/*" {
        pool POOL_POD1_RWSDEVICE
       }
      }
     }
   else
     { ( [HTTP::method] equals "POST" ) } {
     switch -glob [string tolower [HTTP::uri]] {
      "/rws/api/v1/accounts/*" {
        pool POOL_POD1_RWSDEVICE
      }
      default {
        pool POOL_POD1_RWS
      }
     }
    }
   }
   

2 Replies

  • You should copy these iRules as is.
    First iRule

    when HTTP_REQUEST priority 500 {
    
        set URI [string tolower [HTTP::uri]]
    
        if { ( [HTTP::method] == "PUT" ) } {
            switch -- -glob ${URI} {
                "/rws/api/v1/devices/*" -
                "/rws/api/v1/accounts/*"
                {
                    pool POOL_POD1_RWSDEVICE
                }
            }
        } elseif { ( [HTTP::method] == "POST" ) } {
            switch -- -glob ${URI} {
                "/rws/api/v1/accounts/*"
                {
                    pool POOL_POD1_RWSDEVICE
                }
                default
                {
                    pool POOL_POD1_RWS
                }
            }
        }
    
    }

    Second iRule

    when HTTP_REQUEST priority 500 {
    
        if { ( [HTTP::method] == "PUT" ) } {
            switch -- -glob ${URI} {
                "/x/*" -
                "/y/*"
                {
                    pool PUT_X_Y
                }
            }
        } elseif { ( [HTTP::method] == "POST" ) } {
            switch -- -glob ${URI} {
                "/x/*"
                {
                    pool POST
                }
            }
        }
        default {
            pool POOL1
        }
    
    }

     

  • when HTTP_REQUEST {
      if { ( [HTTP::method] equals "PUT" ) } {
        switch -glob [string tolower [HTTP::uri]] {
          "/x/*" -
          "/y/*" {
            pool PUT_X_Y
           }
          }
         }
       elseif
         { ( [HTTP::method] equals "POST" ) } {
         switch -glob [string tolower [HTTP::uri]] {
          "/x/*" {
            pool POST
          }
          }
          }
      default {
            pool POOL1
         }
        }