Forum Discussion

David_M's avatar
David_M
Icon for Cirrostratus rankCirrostratus
Jun 24, 2019

How to use the ":1" in irules with HTTP:QUERY?

Hi

I have this irule:

when HTTP_REQUEST {
	if { [HTTP::uri] equals "/example1" } {
		HTTP:redirect https:// [getfield [HTTP:host] ":" 1 ][HTTP:uri] 
	}

I found this from some exam questions, how the : work here, does it split the uri or host based on the port number or something?

Couldn't find any doc on the use of : in irules!

  • Hi DavidMas,

     

    the iRule redirects you to a destination setup by a concatenated string. The portions of the string are https:// followed by the value of [getfield [HTTP:host] ":" 1 ] followed by the original [HTTP:uri] the client has currently requested (e.g. "https://www.domain.de/example1").

     

    The nested [getfield [HTTP:host] ":" 1 ] command extracts at first the [HTTP::host] value from the HTTP request (e.g. could be www.domain.com or www.domain.com:80) and then passes the output to the outer [getfield] command, which then splits the value on each single : character and finally outputs just the first element (e.g. www.domain.com:80 will become www.domain.com) back to the concatenated string.

     

    Cheers, Kai

3 Replies

  • Hi DavidMas,

     

    the iRule redirects you to a destination setup by a concatenated string. The portions of the string are https:// followed by the value of [getfield [HTTP:host] ":" 1 ] followed by the original [HTTP:uri] the client has currently requested (e.g. "https://www.domain.de/example1").

     

    The nested [getfield [HTTP:host] ":" 1 ] command extracts at first the [HTTP::host] value from the HTTP request (e.g. could be www.domain.com or www.domain.com:80) and then passes the output to the outer [getfield] command, which then splits the value on each single : character and finally outputs just the first element (e.g. www.domain.com:80 will become www.domain.com) back to the concatenated string.

     

    Cheers, Kai

    • David_M's avatar
      David_M
      Icon for Cirrostratus rankCirrostratus

      Alright . .thanks for the detailed answer:

      The request I have is this . ..So I see it does not have any " : " char means nothing will be split at all, right?

      GET /example1/?id=1 HTTP/1.0 
      Host: www.example2.com
  • Hi DavidMas,

     

    that's right. The [gefield] command simply tries to split on each : character. If no : is included in the input string, the resulting list (its created internally by the getfield command) will contain just a single element holding the original input string.

     

    Cheers, Kai