Forum Discussion

Dustin_Smith_29's avatar
Dustin_Smith_29
Icon for Nimbostratus rankNimbostratus
Feb 09, 2007

How to add a query string value to pass to servers in teh pool?

 

I would like to add a query string value to the incoming http request to distinguish on the server if it is coming in on an ssl virtual or not.

 

 

Example 1

 

 

From

 

https://www.somedomain.com/somepage.aspx

 

To

 

https://www.somedomain.com/somepage.aspx?issecure=y

 

 

OR

 

 

From

 

https://www.somedomain.com/somepage.aspx?someothername=800

 

To

 

https://www.somedomain.com/somepage.aspx?someothername=800&issecure=y

 

 

Anyone have some input to how we cold do this. I am an iRule novice.

 

 

9 Replies

  • Steve_Brown_882's avatar
    Steve_Brown_882
    Historic F5 Account
    Having issues with a similare irule wondering if anyone has thoughts.

     

     

    The latest iteration looks almost exaclty like Joe's, but no matter what I do it does not seem to append the my new query string to the URI.

     

     

    when HTTP_REQUEST {

     

    set content [HTTP::uri]

     

    set query "somequery=something"

     

    if { ($content starts_with "/print/") and ($content ends_with "?") } {

     

    HTTP::uri "[HTTP::uri]$query"

     

    log "This should be the new uri [HTTP::uri]"

     

    } elseif { ($content starts_with "/print/") and ($content contains "?") } {

     

    HTTP::uri "[HTTP::uri]&$query"

     

    log "This should be the new uri [HTTP::uri]"

     

    } elseif { $content starts_with "/print/" } {

     

    HTTP::uri "[HTTP::uri]?$query"

     

    log "This should be the new uri [HTTP::uri]"

     

    }

     

    }
  • Steve_Brown_882's avatar
    Steve_Brown_882
    Historic F5 Account
    To provie a litte more feedback when I change the code to add this

     

     

    if { ($content starts_with "/print/") and ($content ends_with "?") } {

     

    set test "[HTTP::uri]$query]"

     

    HTTP::uri "[HTTP::uri]$query"

     

    log "This should be the new uri $test [HTTP::uri]"

     

     

     

    I see the new query string in the log. Is this simpley an issue were the uri is updated but it won't show in the log?
  • Can you provide an example of what the original uri looks like and what you want it to look like after its been appended?

     

     

    CB
  • Steve_Brown_882's avatar
    Steve_Brown_882
    Historic F5 Account
    basically I am looking to append it something along the lines of "&sometest=something" The uri will look something like /print/sometstuff/ and may or may not have an existing query string hence the conditions. I also tried appending the HTTP::query and then appending the HTTP:uri with [HTTP::path][HTTP::query] with the same result.
  • stjbrown, the value for HTTP::uri and most other HTTP:: commands is cached within the same iRule event. You can see the updated value by adding a second HTTP_REQUEST event with a priority that triggers after the defautl priority of 500:

     
     when HTTP_REQUEST { 
       set query_args "p1=v1" 
      
       log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]" 
       if { [HTTP::uri] ends_with "?" } { 
          http://www.foo.com/bar? -> http://www.foo.com/bar?p1=v1 
         HTTP::uri "[HTTP::uri]$query_args" 
       } elseif { [HTTP::uri] contains "?" } { 
          http://www.foo.com/bar?a=b -> http://www.foo.com/bar?a=b&p1=v1 
         HTTP::uri "[HTTP::uri]&$query_args" 
       } else { 
          http://www.foo.com/bar -> http://www.foo.com/bar?p1=v1 
         HTTP::uri "[HTTP::uri]?$query_args" 
       } 
     } 
     when HTTP_REQUEST priority 501 { 
       log local0. "[IP::client_addr]:[TCP::client_port]: (501) Updated URI: [HTTP::uri]" 
      
     } 
     

    Aaron
  • Steve_Brown_882's avatar
    Steve_Brown_882
    Historic F5 Account
    Thanks for the follow up, but this still does not seem to function as I would expect. Basically everything works accept it I never see and actual & logged. So for the example above if the entered URL were "http://www.foo.com/bar" It is changed to "http://www.foo.com/bar?p1=v1" just fine. However if the URL is "http://www.foo.com/bar?a=b" I get this in the logs. "http://www.foo.bar?a=bp1=v1". Notice the missing & in the second example. I tried eascabing the & with a backslash, but no luck.
  • An initial request of http://www.foo.com/bar?a=b should match this clause:

     
        } elseif { [HTTP::uri] contains "?" } {  
           http://www.foo.com/bar?a=b -> http://www.foo.com/bar?a=b&p1=v1  
          HTTP::uri "[HTTP::uri]&$query_args"  
     

    and the query string argument should be appended after an ampersand. Can you add logging to each case and log the output of the URI update using this as an example:

     
     when HTTP_REQUEST { 
        set query_args "p1=v1" 
      
        log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]. Appending $query_args." 
        if { [HTTP::uri] ends_with "?" } { 
            http://www.foo.com/bar? -> http://www.foo.com/bar?p1=v1 
           HTTP::uri "[HTTP::uri]$query_args" 
           log local0. "[IP::client_addr]:[TCP::client_port]: URI ends with ?" 
        } elseif { [HTTP::uri] contains "?" } { 
            http://www.foo.com/bar?a=b -> http://www.foo.com/bar?a=b&p1=v1 
           HTTP::uri "[HTTP::uri]&${query_args}" 
           log local0. "[IP::client_addr]:[TCP::client_port]: URI contains ?" 
        } else { 
            http://www.foo.com/bar -> http://www.foo.com/bar?p1=v1 
           HTTP::uri "[HTTP::uri]?$query_args" 
           log local0. "[IP::client_addr]:[TCP::client_port]: URI does not contain ?" 
        } 
     } 
     when HTTP_REQUEST priority 501 { 
        log local0. "[IP::client_addr]:[TCP::client_port]: (501) Updated URI: [HTTP::uri]" 
     } 
     

    Thanks,

    Aaron
  • I have a similar situation but slightly different in the sense that my query parameters is quite different from the one above.

    http://10.10.1.57:9001/forms/frmservlet?config=ref&serveruserparams=NLS_LANG=AMERICAN_AMERICA.AR8MSWIN1256&otherparams=P_WST_LAN_IND=1+P_BANKS_APP_URL=http://10.10.1.57:9001/banks
    

    The intended uri is what I have above but, I want clients to access http://10.10.1.57:9001/ and be directed to

    http://10.10.1.57:9001/forms/frmservlet?config=ref&serveruserparams=NLS_LANG=AMERICAN_AMERICA.AR8MSWIN1256&otherparams=P_WST_LAN_IND=1+P_BANKS_APP_URL=http://10.10.1.57:9001/banks

    That is the full query string that should accessed.

    Please note that 10.10.1.57:9001 is the virtual IP and it is load-balanced to the pool thereafter.

  • I've answered this question in OP other post: https://devcentral.f5.com/s/feed/0D51T00006j41ULSAY