Forum Discussion

abachman_72712's avatar
abachman_72712
Icon for Nimbostratus rankNimbostratus
Aug 21, 2009

Append to uri

I need to append to the uri that the user types. The client browser needs to see the addition for a certain java function to work properly. We are using an existing iRule for cookie persistence, and need to add to the existing iRule:

 

 

Here is the existing iRule:

 

 

when HTTP_RESPONSE {

 

if { [HTTP::cookie exists "JSESSIONID"] } {

 

persist add uie [HTTP::cookie "JSESSIONID"]

 

}

 

}

 

when HTTP_REQUEST {

 

log local0. "Request: [HTTP::uri]"

 

if { [HTTP::cookie exists "JSESSIONID"] } {

 

persist uie [HTTP::cookie "JSESSIONID"]

 

} else {

 

set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"]

 

if { $jsess != "" } {

 

persist uie $jsess

 

}

 

}

 

}

 

 

Here is what I am trying to add into the iRule:

 

 

when HTTP_REQUEST { if {[HTTP::uri] starts_with "/cc/Claim"} {

 

HTTP::redirect http://[HTTP::host]/cc/Claim/Claim.do

 

}

 

}

 

 

Any help would be appreciated?

 

10 Replies

  • You could consider:

     

       
     when HTTP_REQUEST { if {[HTTP::uri] starts_with "/cc/Claim"} {   
     HTTP::uri /cc/Claim/Claim.do   
     }   
     }   
     

     

    ...which will transparently pass the uri back to the server without the redirect. That said, your redirect idea should work as well. You should be able to add your if test code (or the untested code in the if block above) just after your persist command above in the HTTP_REQUEST event.

     

     

    -Matt
  • As Matt suggested, if you want to redirect the client, you should do it before anything else in the HTTP_REQUEST event:

     
     when HTTP_REQUEST {  
      
        log local0. "Request: [HTTP::uri]"  
        if {[HTTP::uri] starts_with "/cc/Claim"}{  
           HTTP::redirect "http://[HTTP::host]/cc/Claim/Claim.do" 
        } elseif { [HTTP::cookie exists "JSESSIONID"] } { 
           persist uie [HTTP::cookie "JSESSIONID"]  
        } else {  
           set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"]  
           if { $jsess != "" } {  
              persist uie $jsess  
           }  
        }  
     } 
      
     when HTTP_RESPONSE {  
      
        if { [HTTP::cookie exists "JSESSIONID"] } {  
           persist add uie [HTTP::cookie "JSESSIONID"]  
        }  
     }  
     

    Aaron
  • Aaron - good catch, thanks for clarifying this. Re-reading my original post this wasn't clear at all...sigh.

     

    -Matt
  • Thanks guys. The URI is working and I can get to the logon screen with the modifications you suggested, but the user's browser still only shows http://cc/Claim. Is there a command I can add in to get the /claim.do to show up in the uri line of the user's browser. This is needed for the java piece to work.

     

     

    when HTTP_REQUEST {

     

    log local0. "Request: [HTTP::uri]"

     

    if {[HTTP::uri] starts_with "/cc/Claim"}{

     

    HTTP::redirect "http://[HTTP::host]/cc/Claim/Claim.do"

     

    } elseif { [HTTP::cookie exists "JSESSIONID"] } {

     

    persist uie [HTTP::cookie "JSESSIONID"]

     

    } else {

     

    set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"]

     

    if { $jsess != "" } {

     

    persist uie $jsess

     

    }

     

    }

     

    }

     

    when HTTP_RESPONSE {

     

    if { [HTTP::cookie exists "JSESSIONID"] } {

     

    persist add uie [HTTP::cookie "JSESSIONID"]

     

    }

     

    }

     

     

    Thanks
  • Use the redirect method Aaron outlines above in that case. By using HTTP::uri we're quite literally redefining the URI just before it passes back to the server - so the client is clueless about the change. This is fairly effective as a resource cloaking trick but in your case it sounds like the 302 is the way to go.

     

     

    -Matt
  • Sorry: just to clarify, are you using the HTTP::uri method or the HTTP::redirect method? The post above shows a redirect but you mention that the URI is concealed from the client which implies using HTTP::uri. I fully expect the redirect to honor the URI and for it to be seen at the client...is this not the case? Can you capture some headers and paste them in so we can see the behavior?

     

     

    -Matt
  • I believe I am using the HTTP::redirect method recommended, would you agree from the posted iRule? With the redirect syntax, the claim.do is not appearing in the client browser.

     

     

    Are you looking for some TCPdump captures off the bigIp?
  • If the client is making a request to /cc/Claim using the above iRule, they should get redirected to /cc/Claim/Claim.do. I'd guess either there is a mismatch in the URI listed in the rule versus what the client is requesting or the redirect is being made but the client isn't seeing it possibly because another redirect from the app. Can you add logging to the iRule and use a browser plugin as Matt was alluding to like HttpFox for Firefox or Fiddler for IE?

     
      when HTTP_REQUEST {   
      
         log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::uri]" 
      
         if {[HTTP::uri] starts_with "/cc/Claim"}{ 
      
            log local0. "[IP::client_addr]:[TCP::client_port]: Matched URI check, redirecting to http://[HTTP::host]/cc/Claim/Claim.do" 
            HTTP::redirect "http://[HTTP::host]/cc/Claim/Claim.do"  
      
         } elseif { [HTTP::cookie exists "JSESSIONID"] } {  
      
            log local0. "[IP::client_addr]:[TCP::client_port]: jsessionid cookie exists, persisting with it." 
            persist uie [HTTP::cookie "JSESSIONID"] 
      
         } else { 
      
            log local0. "[IP::client_addr]:[TCP::client_port]:  Check for jsessionid in URI" 
            set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"] 
            if { $jsess != "" } { 
               log local0. "[IP::client_addr]:[TCP::client_port]: Found jsessionid in URI" 
               persist uie $jsess 
            }   
         }   
      }  
      
      when HTTP_RESPONSE {   
      
         if { [HTTP::cookie exists "JSESSIONID"] } { 
            log local0. "[IP::client_addr]:[TCP::client_port]: Persisting based on response jsessionid cookie" 
            persist add uie [HTTP::cookie "JSESSIONID"] 
         }   
      }   
     

    Aaron
  • I see you may have a redirect loop:

    A tiny test shows:

     
      when HTTP_REQUEST { 
     if { [HTTP::uri] starts_with "/cc/Claim" } { 
      
     HTTP::redirect "http://[HTTP::host]/cc/Claim/Claim.do" 
     } 
     } 
     

    Ends up in a redirect loop for me: firefox shows that "this page isn't redirecting properly" or a similar message. Dumping the HTTP headers confirms this.

    But changing [HTTP::uri] "starts_with" to "ends_with" works properly for me:

     
      when HTTP_REQUEST { 
     if { [HTTP::uri] ends_with "/cc/Claim" } { 
     HTTP::redirect "http://[HTTP::host]/cc/Claim/Claim.do" 
     } 
     if { [HTTP::uri] ends_with "Claim.do" } { 
     HTTP::respond 200 content "You made it!!" 
     } 
     } 
     

    gives me the expected result, as well as the full URI in the browser address bar as expected.

    I hope this helps.

    -Matt

  • Nice catch, Matt. You could also use eq to check for an exact URI of /cc/Claim/ before redirecting:

     

     

    if { [HTTP::uri] eq "/cc/Claim" } {

     

     

    Aaron