Forum Discussion

Silvia_84906's avatar
Silvia_84906
Icon for Nimbostratus rankNimbostratus
May 04, 2010

Remove a parameter from a query

Hi all,

 

I'm trying to remove a parameter from a query and I've tried to do it in so many ways but they didn't work as I expected...

 

 

For example the URL could be:

 

 

And I'd like to eliminate this parameter "X-PROVE-3GPDPContext=yes" from the query without removing the others.

 

I've tried it using the "remove" command for HTTP:query and HTTP:uri.

 

[HTTP::query] remove "X-VODAFONE-3GPDPContext="

 

Also splitting the URI like this:

 

if {($queryM contains "X-PROVE-3GPDPContext")}{

 

 

 

Split the query into name-value pairs delimited by "&"

 

set namevals [split [HTTP::query] "&"]

 

A TCL for loop - if you ever wondered what one looks like...

 

for {set i 0} {$i < [llength $namevals]} {incr i} {

 

if { $::debug>=1 } { log local0. " i: $i" }

 

Split name-value pair into name and value delimited by "="

 

set params [split [lindex $namevals $i] "="]

 

if { $::debug>=1 } { log local0. " parameters: $param" }

 

set name [lindex $params 0]

 

if { $::debug>=1 } { log local0. " nam : $name" }

 

set val [lindex $params 1]

 

if { $::debug>=1 } { log local0. " value : $val" }

 

}

 

 

But I am not able to do it in a right way.

 

Could you help me??

 

Thank you in advance!

 

Silvia

 

4 Replies

  • If you just want to remove that text from the URI going to the server this should work for you.

    This iRule will not remove it from the Displayed URL in the Browser (to remove it from the Browser you would have to remove it from the URI and do a Redirect):

    
    when HTTP_REQUEST {
    if { [HTTP::uri] contains "X-VODAFONE-3GPDPContext=" } {
    HTTP::uri [string map {"X-VODAFONE-3GPDPContext=" ""} [HTTP::uri]]
    }
    }
    
  • If you want to remove the parameter name and value (if present) from the query string, you could try something like this:

    
    when HTTP_REQUEST {
    
        Check if the query string parameter value isn't null
       if {[HTTP::query] contains "X-VODAFONE-3GPDPContext="}{
    
           Use a workaround to parse the parameter value from the query string
           described on http://devcentral.f5.com/wiki/default.aspx/iRules/uri__query
          set param_value [URI::query "?&[HTTP::query] "&X-VODAFONE-3GPDPContext"]
    
           Save a copy of the URI with the param and value removed
          set uri [string map [list "X-VODAFONE-3GPDPContext=$param_value" ""] [HTTP::uri]]
    
           Replace && with & in the updated query string if && is present and set the URI to this
          HTTP::uri [string map "&& &" $uri]
    
           Log the cached and updated values for the URI
          log local0. "Original URI: [HTTP::uri], updated URI: [string map "&& &" $uri]"
       
       }
    }
    

    Aaron
  • The forum munged the &'s in the code block. So replace each & amp ; in the post with &.

     

     

    Aaron