# iRule help with adding a customer header

**URL:** <https://community.f5.com/t/irule-help-with-adding-a-customer-header/11430>\
**Category:** Technical Forums\
**Tags:** cloud, ltm\
**Created:** [April 6, 2017, 11:03am UTC](https://community.f5.com/t/irule-help-with-adding-a-customer-header/11430 "2017-04-06T11:03:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![avnishvyas\_1974](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@avnishvyas\_1974](https://community.f5.com/u/avnishvyas_1974)\
**Post date:** [April 6, 2017, 11:03am UTC](https://community.f5.com/t/irule-help-with-adding-a-customer-header/11430/1 "2017-04-06T11:03:38Z")

</div>

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/](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 “”

}

}

---

<div class="post-metadata">

**Author:** ![Leonardo\_Souza](https://avatars.discourse-cdn.com/v4/letter/l/96bed5/32.png) [@Leonardo\_Souza](https://community.f5.com/u/Leonardo_Souza)\
**Post date:** [April 6, 2017, 11:25am UTC](https://community.f5.com/t/irule-help-with-adding-a-customer-header/11430/2 "2017-04-06T11:25:51Z")

</div>

Yes, should work.

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

Headers without iRule:

```tcl
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:

```tcl
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:

```tcl
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

```
