Forum Discussion

Wes_98712's avatar
Wes_98712
Icon for Nimbostratus rankNimbostratus
Apr 18, 2006

mapclass2node

I have the following v4 rule within the pool as a node select expression:

 

 

V4 CODE:

 


mapclass2node(findstr(http_uri, "srv=", 4, '&'), urlaff_retailcf)

 

 

The class looks as follows:

 

V4 CODE:

 


class urlaff_retailcf {
    "srv2 10.34.238.31:80"
    "srv3 10.34.238.26:80"
}

 

 

What I need to know is how would I handle this in v9? Something as follows?

 

 


when HTTP_REQUEST {   
   set my_uri [HTTP::uri]
   set my_query [HTTP::query]
   if {[HTTP::host] equals "www.somehost.com"} {
      set my_findstr [findstr $my_uri "srv=" "&", 4]   
      node [findclass $my_findstr $::urlaff_retailcf " "]
   }
}

 

 

I'm thinking that would work, but not sure of the syntax, if someone could proof it that would be great. For this legacy cold fusion site we have to persist based on the URI query looking for srv= which then maps back to a specific server, referenced in the class.

 

 

Thanks,

 

 

-wn

 

 

1 Reply

  • You are pretty darn close. The only thing I see that is sticking out is that you have the findstr arguments in the wrong place. The skip count of 4 should be before the termination character and you have a comma in there that would also cause a load error.

     

     

    One other point is that you might want to put some sanity checks in there. What happens if there is no "srv=" GET parameter? Then findstr will return an empty string and you will call the node command with an empty string. Probably not what you intended. Here's your rule with a few sanity checks included

     

     

    when HTTP_REQUEST {   
       if {[HTTP::host] equals "www.somehost.com"} {
          set my_findstr [findstr [HTTP::uri] "srv=" 4 "&"]
          if { [string length $my_findstr] > 0 } {
            set new_node [findclass $my_findstr $::urlaff_retailcf " "]
            if { [string length $new_node] > 0 } {
              node $new_node
            }
          }
       }
    }

     

     

    *disclaimer, this code hasn't been fully tested.

     

     

    -Joe