Forum Discussion

stucky101_88485's avatar
stucky101_88485
Icon for Nimbostratus rankNimbostratus
Feb 22, 2013

Assign dgl key directly to tcl var instead of having to define value first ?

Gurus

 

I'm trying to write an iRule that looks through a dgl and left trims strings it finds there from the URI, then redirects to a new url with this trimmed uri.

 

The following does what I want:

 

DGL:

 

/rma/ := /rma/

 

iRule:

 

when HTTP_REQUEST {

 

Check if uri needs trimming

 

if { [class match [HTTP::uri] starts_with trim_uri_starts_with] } {

 

set trim [class match -value [HTTP::uri] starts_with trim_uri_starts_with]

 

if { $trim ne "" } {

 

set new_uri [string trimleft [HTTP::uri] $trim]

 

HTTP::redirect http://newhost.domain.com/$new_uri

 

}

 

}

 

}

 

However, it ocurred to me that this requires both key and value when really I only need the key since key and value always need to be exactly the same.

 

Seems redundant to me. Basically I'm trying to say "If your uri starts_with a string found in the dgl then left trim exactly that string". So I figured rather than reading

 

a value from the key that is the same as the key anyways why not read the key directly so I tried this :

 

when HTTP_REQUEST {

 

Check if uri needs trimming

 

if { [class match [HTTP::uri] starts_with trim_uri_starts_with] } {

 

set trim [class match [HTTP::uri] starts_with trim_uri_starts_with]

 

log local0. "trim is set to $trim"

 

if { $trim ne "" } {

 

set new_uri [string trimleft [HTTP::uri] $trim]

 

HTTP::redirect http://newhost.domain.com/$new_uri

 

}

 

}

 

}

 

but this doesn't work because I guess you cannot assing the key itself to a tcl var ? It gets set to 1 if there is a match as the log showed me.

 

It just seems so redundant to have to define a value matching exactly the key for every uri u wanna trim. What bugs me is I know the f5 reads the key otherwise it couldn't compare

 

it to the actual uri but can I capture it as a tcl var ?

 

thx

 

2 Replies

  • Have you tried something like this?

    
    when HTTP_REQUEST {
    
      set uri_key [URI::path [HTTP::uri] 1]
      if { [class match $uri_key uri_datagroup] } {
          HTTP::redirect http://newhost.domain.com/$uri_key
      }
    
    }
     
  • I see. U had a small typo there where u forgot the operator after "$uri_key". This following works :

     

    when HTTP_REQUEST {

     

    set uri_key [URI::path [HTTP::uri] 1]

     

    if { [class match $uri_key equals trim_uri_starts_with] } {

     

    set new_uri [string trimleft [HTTP::uri] $uri_key]

     

    HTTP::redirect http://newhost.domain.com/$new_uri

     

    }

     

    }

     

     

    Thank you !