# insert field to HTTP header

**URL:** <https://community.f5.com/t/insert-field-to-http-header/10052>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [March 27, 2008, 6:57pm UTC](https://community.f5.com/t/insert-field-to-http-header/10052 "2008-03-27T18:57:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![skarpovi\_111573](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@skarpovi\_111573](https://community.f5.com/u/skarpovi_111573)\
**Post date:** [March 27, 2008, 6:57pm UTC](https://community.f5.com/t/insert-field-to-http-header/10052/1 "2008-03-27T18:57:48Z")

</div>

can BIG-IP insert field data into the HTTP header that the IIS server can then read and use to determine whether or not the user in question is coming from our internal environment or from the public networks

---

<div class="post-metadata">

**Author:** ![Nicolas\_Menant\_1](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@Nicolas\_Menant\_1](https://community.f5.com/u/Nicolas_Menant_1)\
**Post date:** [March 27, 2008, 7:02pm UTC](https://community.f5.com/t/insert-field-to-http-header/10052/2 "2008-03-27T19:02:39Z")

</div>

Hi,

Yes it’s possible with the HTTP::header insert command: [Click here](http://devcentral.f5.com/wiki/default.aspx/iRules.HTTP)

when HTTP\_REQUEST {

HTTP::header insert header\_1 value\_3

log local0. “new header header\_1 inserted with a value of [HTTP::header “header\_1”]”

}

---

<div class="post-metadata">

**Author:** ![skarpovi\_111573](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@skarpovi\_111573](https://community.f5.com/u/skarpovi_111573)\
**Post date:** [March 27, 2008, 8:31pm UTC](https://community.f5.com/t/insert-field-to-http-header/10052/3 "2008-03-27T20:31:52Z")

</div>

what is header\_1 value\_3 and why do i need log local0.

---

<div class="post-metadata">

**Author:** ![The\_Bhattman](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/the_bhattman/32/13958_2.png) [@The\_Bhattman](https://community.f5.com/u/The_Bhattman)\
**Post date:** [March 27, 2008, 9:38pm UTC](https://community.f5.com/t/insert-field-to-http-header/10052/4 "2008-03-27T21:38:52Z")

</div>

Header\_1 represents a header name such as “user” or “host”

value\_3 represents the actual value of “user” or “host”

log local0. Tells the iRULE to log the message between quotes to the ltm log file within BIGIP.

---

<div class="post-metadata">

**Author:** ![Nicolas\_Menant\_1](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@Nicolas\_Menant\_1](https://community.f5.com/u/Nicolas_Menant_1)\
**Post date:** [March 28, 2008, 2:08am UTC](https://community.f5.com/t/insert-field-to-http-header/10052/5 "2008-03-28T02:08:14Z")

</div>

Exactly

I would strongly advise you to check how those commands work by looking at the wiki since you seem not to know much about iRules

it will help you a lot

---

<div class="post-metadata">

**Author:** ![skarpovi\_111573](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@skarpovi\_111573](https://community.f5.com/u/skarpovi_111573)\
**Post date:** [March 28, 2008, 5:51pm UTC](https://community.f5.com/t/insert-field-to-http-header/10052/6 "2008-03-28T17:51:30Z")

</div>

OK, i guess i have to reinstate the question and describe my situation.

we have site: [mycomany.com](http://mycomany.com) where IIS doing automaticaly redirect to the page

when users go to this site on port 80, we use BigIP iRule & redirect to port 443

Now, after we implemented trusted sign-on for internal users, based on source IP we want to redirect them to different authentication page.

we can’t use HTTP::redirect, since IIS doing some redirection automatacaly, in which case we will have [NameBright - Coming Soon](http://mycomany.com/%22BigIP-redirect%22)“IIS redirect” as one string in URL

We want to use HTTP header insert string, which vill be recognized by IIS and present different authentication based on the IP source.

I guess: Header\_1 represents a header name such as “user” or “host” value\_3 represents the actual value of “user” or “host”

not going to do much, since i don’t care about “user” and “host” - destination will be the same.

so, what are my options. where in this statement i can insert HTTP::header rule? and how does it going to look like?

how will it come across i.e.( STRING=1, STRING=true, or just the mere existence of STRING, which will signifies different source IP)

when HTTP\_REQUEST {

if {([TCP::local\_port] eq “80”) and ([IP::client\_addr] eq “10.x.x.x/16”)} {

HTTP::redirect “https://[HTTP::host][HTTP::uri]”

} elseif {[TCP::local\_port] eq “80” } {

HTTP::redirect “http://[HTTP::host][HTTP::uri]”

} else {

pool Servers-Pool

}

}

---

<div class="post-metadata">

**Author:** ![Nicolas\_Menant\_1](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@Nicolas\_Menant\_1](https://community.f5.com/u/Nicolas_Menant_1)\
**Post date:** [March 28, 2008, 6:54pm UTC](https://community.f5.com/t/insert-field-to-http-header/10052/7 "2008-03-28T18:54:19Z")

</div>

Hi,

What we gave you is an example of the syntax -\_- not the solution. It was to help you understand the syntax.

You should have tried some search on this forum to find the answer by yourself…

When you do a redirect you can insert anything in the header so in your iRule you can insert HTTP header only in your else statement

If you had read the documentation about the HTTP::header insert you would have understand that header\_1 would have been a new header created in the HTTP request which name would have been header 1 and its value would be the following data so in my example it would be value\_3.

So to make it easy to understand:

```tcl
when HTTP_REQUEST {
  if {([TCP::local_port] eq "80") and ([IP::client_addr] eq "10.x.x.x/16")} {
    HTTP::redirect "https://[HTTP::host][HTTP::uri]"
  } elseif {[TCP::local_port] eq "80" } {
    HTTP::redirect "http://[HTTP::host][HTTP::uri]"
  } else {
    HTTP::header insert STRING HERE_YOU_SPECIFY_THE_VALUE_YOU_WANT_STRING_TO_HAVE
    pool Servers-Pool
  }
}

```

---

<div class="post-metadata">

**Author:** ![skarpovi\_111573](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@skarpovi\_111573](https://community.f5.com/u/skarpovi_111573)\
**Post date:** [March 31, 2008, 7:46pm UTC](https://community.f5.com/t/insert-field-to-http-header/10052/8 "2008-03-31T19:46:45Z")

</div>

will it work this way???

if comming from address, inseart string, then look for port and redirect. (server will see string and based on the string presence will provide different page)

when HTTP\_REQUEST {

if {[IP::client\_addr] eq “10.0.0.0/16”} {

HTTP::header insert STRING MLint

}

if {[TCP::local\_port] eq “80”} {

HTTP::redirect “https://[HTTP::host][HTTP::uri]”

} else {

pool eRoom-Servers-Pool

}

}

---

<div class="post-metadata">

**Author:** ![The\_Bhattman](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/the_bhattman/32/13958_2.png) [@The\_Bhattman](https://community.f5.com/u/The_Bhattman)\
**Post date:** [March 31, 2008, 9:19pm UTC](https://community.f5.com/t/insert-field-to-http-header/10052/9 "2008-03-31T21:19:11Z")

</div>

When you do this the logic will be

If client ip address equals 10.0.0.0/16 then insert or if the port = 80 then redirect, else go to pool.

It sounds like you need it to get past the first IF statement, before it checks the port, which is what your example wouldn’t do.

In that case perhaps you might want to do it the following:

```tcl
when HTTP_REQUEST {
if { [IP::addr 10.0.0.0/16 eq [IP::client_addr]] } { 
    HTTP::header insert STRING MLint 
    if { [TCP::local_port eq "80" } {
         HTTP::redirect "https://[HTTP::host][HTTP::uri]"
    } else {
    pool eRoom-Servers-Pool
    }
   }
}

```

Hope that helps

/CB

---

<div class="post-metadata">

**Author:** ![skarpovi\_111573](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@skarpovi\_111573](https://community.f5.com/u/skarpovi_111573)\
**Post date:** [April 1, 2008, 1:09pm UTC](https://community.f5.com/t/insert-field-to-http-header/10052/10 "2008-04-01T13:09:48Z")

</div>

tried to use this iRule, didn’t get any errors, but at the same time didn’t see any string incerted in Header. it does https redirect. Is there any other way to see that incert in header? i use ieHTTPheaders software to view. is anything else needs to be done on the BigIP side to enable this future.

thanks in advance for your help.

GET / HTTP/1.0

Accept: \*/\*

Accept-Language: en-us

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MRA 5.0 (build 02094); .NET CLR 2.0.50727; IEMB3)

Host: BigIP-VIP-IP

Connection: Keep-Alive

X-NovINet: v1.2

HTTP/1.0 302 Found

Location: [https://BigIP-VIP-IP/](https://BigIP-VIP-IP/)

Server: BIG-IP

Connection: Keep-Alive

Content-Length: 0
