Forum Discussion

maximillean_953's avatar
maximillean_953
Icon for Nimbostratus rankNimbostratus
May 26, 2014

add header based on request

Hi,

 

I try to write an irule based on request for example.

 

request comes as 10.1.1.1/1.xml so my rule has to apply when request ends with ".xml" i want to add response header X-Robots-Tag "noindex" value.

 

when handling i have to handle request or response dont know that if i can handle both at the same time while writing rule? how would you guys write this rule?

 

Note: I want it to work on 404's too so add only reponse header is not an option it must check request and handle response. not that if reponse is accurate 200 and add header. I want to see header added on 404's too.

 

2 Replies

  • e.g.

     config
    
    [root@ve11a:Active:In Sync] config  tmsh list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        pool foo
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 32
    }
    [root@ve11a:Active:In Sync] config  tmsh list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      if { [string tolower [HTTP::path]] ends_with ".xml" } {
        set add_header 1
      } else {
        set add_header 0
      }
    }
    when HTTP_RESPONSE {
      if { $add_header } {
        HTTP::header insert "X-Robots-Tag" "noindex"
      }
    }
    }
    
     test
    
    [root@ve11a:Active:In Sync] config  curl -I http://172.28.24.10/1.html
    HTTP/1.1 404 Not Found
    Date: Mon, 26 May 2014 14:48:02 GMT
    Server: Apache/2.2.3 (CentOS)
    Content-Type: text/html; charset=iso-8859-1
    
    [root@ve11a:Active:In Sync] config  curl -I http://172.28.24.10/1.xml
    HTTP/1.1 404 Not Found
    Date: Mon, 26 May 2014 14:48:06 GMT
    Server: Apache/2.2.3 (CentOS)
    Content-Type: text/html; charset=iso-8859-1
    X-Robots-Tag: noindex