Forum Discussion

igeo's avatar
igeo
Icon for Nimbostratus rankNimbostratus
Mar 04, 2022

Trim parentheses via tcl

I have the following URL and would like to remove the parentheses (both) by using an iRule (TCL):

 

 

 

http://ing1.example.com:31100/test1/test1.json/Streams(Type_4000000)

 

 

 

 

 

when HTTP_REQUEST {
  if { ([HTTP::host] eq "ing1.example.com") or ([HTTP::host] eq "ing1.example.com" ) and ([HTTP::uri] contains "Streams")}
      set NEW_URI [string trimleft [HTTP::uri] ( or )]
  }

 

 

 

Is it configured correctly?

thank you.

 

  • when HTTP_REQUEST priority 500 {
        if { ([HTTP::host] eq "ing1.example.com:31100") and ([HTTP::uri] contains "Streams") } {
            set old_uri [HTTP::uri]
            HTTP::uri "[string map {( "" ) ""} $old_uri]"
        }
    }

3 Replies

  • xuwen's avatar
    xuwen
    Icon for Cumulonimbus rankCumulonimbus

    use string map to remove :

    tcl test:

    (bin) 68 % set uri "/test1/test1.json/Streams(Type_4000000)"
    /test1/test1.json/Streams(Type_4000000)
    (bin) 69 % set new_uri [string map {( "" ) ""} $uri]
    /test1/test1.json/StreamsType_4000000
    (bin) 70 % 

     

    • igeo's avatar
      igeo
      Icon for Nimbostratus rankNimbostratus

      There was an error when trying to save, so I added braces {}

      {set new_uri [string map {( "" ) ""} $uri]}

      However, this iRule doesn't remove the parentheses. The URL contains also a port, is it needed at the HTTP::host ?

      • xuwen's avatar
        xuwen
        Icon for Cumulonimbus rankCumulonimbus
        when HTTP_REQUEST priority 500 {
            if { ([HTTP::host] eq "ing1.example.com:31100") and ([HTTP::uri] contains "Streams") } {
                set old_uri [HTTP::uri]
                HTTP::uri "[string map {( "" ) ""} $old_uri]"
            }
        }