Forum Discussion

Craig_Gibb_1781's avatar
Craig_Gibb_1781
Icon for Nimbostratus rankNimbostratus
May 25, 2015

Problems with string map and wildcard

Hi i need to replace a string av characters in a uri but only if the uri starts with the following:- /MacBlue_SAMTV/GetAttachmentDownloadInfo

I have tried to do this with the following irule:-

 Check host and path for relevant link
     when HTTP_REQUEST { 
 if { [HTTP::uri] starts_with "/MacBlue_SAMTV/GetAttachmentDownloadInfo" and [HTTP::uri]
  contains "&encoding=TVOD_*_*" } {         

 Replace encoding with MPEG-4
string map { "encoding=TVOD_*_*" "&encoding=MPEG-4" "&encoding=TVOD_*_*" "&encoding=MPEG-4" } HTTP::uri }
}

This does not seem to work, it maybe the wildcards, any suggestions ? Would it be the best way to do this as regards performance.

/Craig

8 Replies

  • what about this?

     configuration
    
    [root@ve11c:Active:In Sync] config  tmsh list ltm rule qux
    ltm rule qux {
        when RULE_INIT {
      set static::uri "/MacBlue_SAMTV/GetAttachmentDownloadInfo"
      set static::param_name "encoding"
      set static::param_value "TVOD_"
      set static::param_newvalue "MPEG-4"
    }
    when HTTP_REQUEST {
      log local0. "before: uri=[HTTP::uri]"
      if { [HTTP::uri] starts_with $static::uri } {
        set value [URI::query [HTTP::uri] $static::param_name]
        if { $value starts_with $static::param_value } {
          HTTP::query [string map [list $static::param_name=$value $static::param_name=$static::param_newvalue] [HTTP::query]]
        }
      }
    }
    when HTTP_REQUEST priority 1000 {
      log local0. "after: uri=[HTTP::uri]"
    }
    }
    
     /var/log/ltm
    
    May 26 11:42:15 ve11c info tmm[32414]: Rule /Common/qux : before: uri=/something
    May 26 11:42:15 ve11c info tmm[32414]: Rule /Common/qux : after: uri=/something
    
    May 26 11:42:32 ve11c info tmm1[32414]: Rule /Common/qux : before: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?something=1234
    May 26 11:42:32 ve11c info tmm1[32414]: Rule /Common/qux : after: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?something=1234
    
    May 26 11:42:42 ve11c info tmm[32414]: Rule /Common/qux : before: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?encoding=TVOD_123_456&test=789
    May 26 11:42:42 ve11c info tmm[32414]: Rule /Common/qux : after: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?encoding=MPEG-4&test=789
    
    May 26 11:42:59 ve11c info tmm1[32414]: Rule /Common/qux : before: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?prefix=abc&encoding=TVOD_123_456&test=789
    May 26 11:42:59 ve11c info tmm1[32414]: Rule /Common/qux : after: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?prefix=abc&encoding=MPEG-4&test=789
    
    • CGI's avatar
      CGI
      Icon for Altostratus rankAltostratus
      Thanks I will give it a go and let you know, could we hav e done this with stream profile ? /Craig
    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      with http profile, stream profile/irule does rewrite http payload only (request and header are not included).
    • CGI's avatar
      CGI
      Icon for Altostratus rankAltostratus
      The rule worked so thanks for the help /Craig
  • what about this?

     configuration
    
    [root@ve11c:Active:In Sync] config  tmsh list ltm rule qux
    ltm rule qux {
        when RULE_INIT {
      set static::uri "/MacBlue_SAMTV/GetAttachmentDownloadInfo"
      set static::param_name "encoding"
      set static::param_value "TVOD_"
      set static::param_newvalue "MPEG-4"
    }
    when HTTP_REQUEST {
      log local0. "before: uri=[HTTP::uri]"
      if { [HTTP::uri] starts_with $static::uri } {
        set value [URI::query [HTTP::uri] $static::param_name]
        if { $value starts_with $static::param_value } {
          HTTP::query [string map [list $static::param_name=$value $static::param_name=$static::param_newvalue] [HTTP::query]]
        }
      }
    }
    when HTTP_REQUEST priority 1000 {
      log local0. "after: uri=[HTTP::uri]"
    }
    }
    
     /var/log/ltm
    
    May 26 11:42:15 ve11c info tmm[32414]: Rule /Common/qux : before: uri=/something
    May 26 11:42:15 ve11c info tmm[32414]: Rule /Common/qux : after: uri=/something
    
    May 26 11:42:32 ve11c info tmm1[32414]: Rule /Common/qux : before: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?something=1234
    May 26 11:42:32 ve11c info tmm1[32414]: Rule /Common/qux : after: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?something=1234
    
    May 26 11:42:42 ve11c info tmm[32414]: Rule /Common/qux : before: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?encoding=TVOD_123_456&test=789
    May 26 11:42:42 ve11c info tmm[32414]: Rule /Common/qux : after: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?encoding=MPEG-4&test=789
    
    May 26 11:42:59 ve11c info tmm1[32414]: Rule /Common/qux : before: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?prefix=abc&encoding=TVOD_123_456&test=789
    May 26 11:42:59 ve11c info tmm1[32414]: Rule /Common/qux : after: uri=/MacBlue_SAMTV/GetAttachmentDownloadInfo?prefix=abc&encoding=MPEG-4&test=789
    
    • CGI's avatar
      CGI
      Icon for Altostratus rankAltostratus
      Thanks I will give it a go and let you know, could we hav e done this with stream profile ? /Craig
    • nitass_89166's avatar
      nitass_89166
      Icon for Noctilucent rankNoctilucent
      with http profile, stream profile/irule does rewrite http payload only (request and header are not included).
    • CGI's avatar
      CGI
      Icon for Altostratus rankAltostratus
      The rule worked so thanks for the help /Craig