Forum Discussion

avnishvyas_1974's avatar
avnishvyas_1974
Icon for Nimbostratus rankNimbostratus
Apr 06, 2017

iRule help with adding a customer header

Im trying to write an iRule for the following if response from a particular URL [] returns a 401 then to add a custom header with WWW-AUTHENTICATE with dummy value BASIC realm="USER VISIBLE REALM" or WWW-Authenticate OATH realm ="http://server.example.com/

 

Will the below do the job?

 

when HTTP_RESPONSE { if { ( [HTTP::status] eq "401" ) and ( [HTTP::header exists WWW-AUTHENTICATE] ) } {

 

HTTP::header replace WWW-Authenticate ""

 

}

 

}

 

1 Reply

  • Yes, should work.

    I just tested the iRule, with small change to match my lab environment.

    Headers without iRule:

    HTTP/1.1 200 OK
    Date: Thu, 06 Apr 2017 11:16:07 GMT
    Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16
    X-Powered-By: PHP/5.4.16
    Set-Cookie: Chocolate=Price%3D1pound; expires=Thu, 06-Apr-2017 11:17:07 GMT
    Set-Cookie: Coconut=Price%3D2pounds; expires=Thu, 06-Apr-2017 11:18:07 GMT
    Content-Length: 503
    Keep-Alive: timeout=5, max=100
    Connection: Keep-Alive
    Content-Type: text/html; charset=UTF-8
    

    iRule:

    when HTTP_RESPONSE { 
      if { ( [HTTP::status] eq "200" ) and ( [HTTP::header exists X-Powered-By] ) } {
        HTTP::header replace X-Powered-By "ok"
      }
    }
    

    Headers after iRule applied to virtual server:

    HTTP/1.1 200 OK
    Date: Thu, 06 Apr 2017 11:18:43 GMT
    Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16
    X-Powered-By: ok
    Set-Cookie: Chocolate=Price%3D1pound; expires=Thu, 06-Apr-2017 11:19:43 GMT
    Set-Cookie: Coconut=Price%3D2pounds; expires=Thu, 06-Apr-2017 11:20:43 GMT
    Content-Length: 497
    Keep-Alive: timeout=5, max=100
    Connection: Keep-Alive
    Content-Type: text/html; charset=UTF-8