# Header Inserts

**URL:** <https://community.f5.com/t/header-inserts/57953>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [November 8, 2011, 5:56pm UTC](https://community.f5.com/t/header-inserts/57953 "2011-11-08T17:56:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wes\_98712](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@Wes\_98712](https://community.f5.com/u/Wes_98712)\
**Post date:** [November 8, 2011, 5:56pm UTC](https://community.f5.com/t/header-inserts/57953/1 "2011-11-08T17:56:12Z")

</div>

I am experiencing a somewhat odd situation. I created an HTTP profile and setup a name value pair in the Request Header Insert (SSL\_ENV:On). When I debug in Fiddler to see if the header is inserted, I don’t see anything which is really strange. So I went the iRule route and tried to test if the header was set and if it wasn’t set it to On:

when HTTP\_REQUEST {

set myhost [HTTP::host]

set myuri [HTTP::uri]

if { ![HTTP::header “SSL\_ENV”] equals “On” } {

HTTP::header insert SSL\_ENV On

log local0. “HEADER HTTPVS: [HTTP::header “SSL\_ENV”]”

} else {

if { $myuri starts\_with “/API” } {

log local0. “URL: $myuri going to non\_ssl pool”

pool pool\_one\_80

} else {

HTTP::redirect “https://$myhost$myuri”

}

}

}

It throws a strange error on the ![HTTP::header

[undefined procedure: !HTTP::header] [!HTTP::header “SSL\_ON”]

I thought inserting a header would be really straight forward and easy, but somehow I am missing something. Thoughts?

BTW: I created the same rule in SSL and HTTP to check if the header didn’t exist and then create it. Still no dice.

---

<div class="post-metadata">

**Author:** ![Michael\_Yates](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@Michael\_Yates](https://community.f5.com/u/Michael_Yates)\
**Post date:** [November 8, 2011, 8:21pm UTC](https://community.f5.com/t/header-inserts/57953/2 "2011-11-08T20:21:55Z")

</div>

Hi Wes,

Try modifying this one line to seperate the functions:

```tcl
FROM: if { ![HTTP::header "SSL_ENV"] equals "On" } {

TO: if { !([HTTP::header "SSL_ENV"] equals "On") } {

```

This will allow the Header value to be found and its value determined first, then does the not compare.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Kurt\_Knochner\_5](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@Kurt\_Knochner\_5](https://community.f5.com/u/Kurt_Knochner_5)\
**Post date:** [November 8, 2011, 9:06pm UTC](https://community.f5.com/t/header-inserts/57953/3 "2011-11-08T21:06:21Z")

</div>

When I debug in Fiddler to see if the header is inserted, I don’t see anything which is really strange.

It’s not so strange as it might look. Besides to syntax error in the iRule (see comment of Michael Yates), Fiddler is the wrong place to look for the header. Fiddler runs on the client and the iRule inserts the HTTP Request header only into requests to the backend servers. So there is no chance to see those modifications in Fiddler at the client. As soon as your iRule works, you could add the following log statement to show the whole request, including any headers:

log local0. “[HTTP::request]”

Simply put that at the end of HTTP\_REQUEST.

Regards

Kurt Knochner

---

<div class="post-metadata">

**Author:** ![Wes\_98712](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@Wes\_98712](https://community.f5.com/u/Wes_98712)\
**Post date:** [November 8, 2011, 11:07pm UTC](https://community.f5.com/t/header-inserts/57953/4 "2011-11-08T23:07:58Z")

</div>

That makes total sense then regarding the HEADER debugging, and the code change above. The strange thing is the variable doesn’t seem to remain static once set. I wonder if I have to do both on the HTTP\_RESPONSE as well as REQUEST.

---

<div class="post-metadata">

**Author:** ![Kurt\_Knochner\_5](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@Kurt\_Knochner\_5](https://community.f5.com/u/Kurt_Knochner_5)\
**Post date:** [November 8, 2011, 11:51pm UTC](https://community.f5.com/t/header-inserts/57953/5 "2011-11-08T23:51:10Z")

</div>

The strange thing is the variable doesn’t seem to remain static once set.

That’s true, as this is just a HTTP request header. That’s not “persistent” like a cookie.

I wonder if I have to do both on the HTTP\_RESPONSE as well as REQUEST.

Why would you want to do that? The client (a browser) will not take care about any special HTTP header, even if you set it in HTTP\_RESPONSE, unless you have javascript or activex code running in the browser that checks that header.

In general you are inserting a certain HTTP request header to add some information to a request. This additional information will be used by the backend application to perform additional operations if that information is present. Based on the name of your header I assume you want to tell the backend application if the original request has been encrypted or not. This will have a meaning for the backend application but not for the client.

Hope that helps.

Regards

Kurt Knochner

---

<div class="post-metadata">

**Author:** ![Wes\_98712](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@Wes\_98712](https://community.f5.com/u/Wes_98712)\
**Post date:** [November 9, 2011, 1:44am UTC](https://community.f5.com/t/header-inserts/57953/6 "2011-11-09T01:44:25Z")

</div>

Make sense, yes the header is telling the backend servers to maintain a secure session, we recently moved to F5 from a different vendor and it would appear that the header variable (ASP server variable) may be displayed differently. The team is checking using something like the following:

```tcl
if Request.ServerVariables("SSL_ENV")="On" then

```

When I dump the REQUEST in the iRule I see the following:

SSL\_ENV: On

It appears F5 is appending the variable with a :, but if I check the value on the F5 in an iRule (e.g., if it exists), the boolean will return true if I specify variable = “On”, but the code doesn’t see that. Not sure if the : is the culprit or what.

Regarding the RESPONSE yes you are correct, there is no client side work going on, this is all on the backend for each request that comes through.

---

<div class="post-metadata">

**Author:** ![Kurt\_Knochner\_5](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@Kurt\_Knochner\_5](https://community.f5.com/u/Kurt_Knochner_5)\
**Post date:** [November 9, 2011, 2:17am UTC](https://community.f5.com/t/header-inserts/57953/7 "2011-11-09T02:17:05Z")

</div>

It appears F5 is appending the variable with a :,

That’s correct, as it’s the syntax for a HTTP header.

name: value

BTW: it’s not a variable, but a HTTP request header.

Regarding your ASP code. I believe the correct way to access the HTTP request header is HTTP\_name\_of\_header, in your case HTTP\_SSL\_ENV, instead of SSL\_ENV.

See also here: [http://www.w3schools.com/asp/coll\_servervariables.asp](http://www.w3schools.com/asp/coll%5C_servervariables.asp)

Regards

Kurt Knochner

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [November 9, 2011, 2:21am UTC](https://community.f5.com/t/header-inserts/57953/8 "2011-11-09T02:21:52Z")

</div>

Regarding your ASP code. I believe the correct way to access the HTTP request header is HTTP\_, in your case HTTP\_SSL\_ENV, instead of SSL\_ENV.i agree with Kurt.

this is another article.

accessing http headers and environment variables

> **[ᐈ eSports News & Tricks (2026) 🥇 ENEWS.GG](https://www.4guysfromrolla.com)**
>
> eSports News, Results, upcoming Matches & live Matches. Learn tricks and guides in the esports space. ✅ We cover CS:GO, Dota 2, LOL, Overwatch & PUBG. 

---

<div class="post-metadata">

**Author:** ![Kurt\_Knochner\_5](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@Kurt\_Knochner\_5](https://community.f5.com/u/Kurt_Knochner_5)\
**Post date:** [November 9, 2011, 2:25am UTC](https://community.f5.com/t/header-inserts/57953/9 "2011-11-09T02:25:57Z")

</div>

we recently moved to F5 from a different vendor

btw. what’s that vendor?

Regards

Kurt Knochner

---

<div class="post-metadata">

**Author:** ![Wes\_98712](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@Wes\_98712](https://community.f5.com/u/Wes_98712)\
**Post date:** [November 9, 2011, 2:27am UTC](https://community.f5.com/t/header-inserts/57953/10 "2011-11-09T02:27:25Z")

</div>

Kurt/Nitass,

Excellent response, thanks a lot for clarifying. I’ll forward on the URLs to the dev team for review, I saw the same articles but noticed that using the other load balancer the same code in place today worked, so it appears F5 (as it should be) adheres more towards industry standards -- good thing. I think this is the source of our issues making sure they reference the header value correctly, I am going to ask them to test both with header\_value: and http\_header\_value and see what works, I’ll post the responses tomorrow.

One last question regarding HTTP\_REQUEST vs HTTP\_REQUEST\_SEND, implementing the insert should be within the initial REQUEST correct? No reason to switch to the REQUEST\_SEND correct?

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [November 9, 2011, 2:30am UTC](https://community.f5.com/t/header-inserts/57953/11 "2011-11-09T02:30:57Z")

</div>

One last question regarding HTTP\_REQUEST vs HTTP\_REQUEST\_SEND, implementing the insert should be within the initial REQUEST correct? No reason to switch to the REQUEST\_SEND correct?since you do not need any information from server-side, inserting it in client-side event i.e HTTP\_REQUEST is fine.

---

<div class="post-metadata">

**Author:** ![Wes\_98712](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@Wes\_98712](https://community.f5.com/u/Wes_98712)\
**Post date:** [November 9, 2011, 5:53pm UTC](https://community.f5.com/t/header-inserts/57953/12 "2011-11-09T17:53:17Z")

</div>

Kurt, we switched from Barracuda. Here’s an update.

I ended up using the http profile header insert and noticed a few interesting things when we debugged the ASP server variables. When we dump the ASP server variables we actually see that somehow HTTP\_ is prepended before the header so it looks like HTTP\_SSL\_ENV, the RAW dump actually shows the exact name. Which is interesting, however, what is really strange is that both the HTTP header dump and the RAW dump show the value of the header, but when we loop through the variables:

```tcl
for each x in Request.ServerVariables
  response.write(x & "*" & Request.ServerVariables(x) & "*
")
next

```

the actual value doesn’t display for SSL\_ENV, it shows up as:

HTTP: HTTP\_SSL\_ENV:On \*

RAW: HTTP\_SSL\_ENV:On \*

But when we loop through the headers the output of the SSL\_ENV is:

HTTP\_SSL\_ENV\*\*

Some how it’s not getting the value of the header.

---

<div class="post-metadata">

**Author:** ![Wes\_98712](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@Wes\_98712](https://community.f5.com/u/Wes_98712)\
**Post date:** [November 9, 2011, 6:30pm UTC](https://community.f5.com/t/header-inserts/57953/13 "2011-11-09T18:30:18Z")

</div>

More on this, it seems as though the Request.ServerVariables isn’t pulling the value of the SSL\_ENV header. The RAW output shows it, but not the actual Request.ServerVariables(x). I don’t believe this is an F5 issue, I did validate that I set the header insert correctly in the profile (SSL\_ENV: On). Stumped!

---

<div class="post-metadata">

**Author:** ![Wes\_98712](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@Wes\_98712](https://community.f5.com/u/Wes_98712)\
**Post date:** [November 9, 2011, 10:54pm UTC](https://community.f5.com/t/header-inserts/57953/14 "2011-11-09T22:54:49Z")

</div>

Another update, after a lot of testing we discovered something odd about the way F5 is inserting the header value

If we use an iRule (HTTP::header insert SSL\_ENV On) or if we set the Request Header Insert in the http profile (SSL\_ENV: On) either way F5 can see the header and reports that the value is set to On, but the server can’t see the value:

```tcl
if Request.ServerVariables("HTTP_SSL_ENV")="On" then
response.write("WES Pass: " & Request.ServerVariables("HTTP_SSL_ENV") & "
")
else
   response.write("WES Fail: " & Request.ServerVariables("HTTP_SSL_ENV:") & "
")
end if

```

The output is always Wes Fail: (kind of ironic). But the ltm logs show the following if I capture the header value in the ltm log:

```tcl
when HTTP_REQUEST {
   if { [HTTP::header "HTTP_SSL_ENV"] equals "On" } {
      log local0. "HEADER HTTPS is: [HTTP::header "HTTP_SSL_ENV"]"
   }
}

```

Results:

Nov 9 15:29:36 tmm info tmm[7845]: Rule /Common/test\_irule : HEADER HTTPS is: On

Nov 9 15:30:06 tmm info tmm[7845]: Rule /Common/test\_irule : HEADER HTTPS is: On

Nov 9 15:30:46 tmm info tmm[7845]: Rule /Common/test\_irule : HEADER HTTPS is: On

Nov 9 15:30:46 tmm info tmm[7845]: Rule /Common/test\_irule : HEADER HTTPS is: On

Nov 9 15:31:38 tmm info tmm[7845]: Rule /Common/test\_irule : HEADER HTTPS is: On

Nov 9 15:31:38 tmm info tmm[7845]: Rule /Common/test\_irule : HEADER HTTPS is: On

So now I’m kind of stuck wondering why ASP can’t read the value in the header using the ServerRequest function, but yet in RAW output or ALL\_HTTP it can. Do I need to do something different with the header insert on the F5?

---

<div class="post-metadata">

**Author:** ![Wes\_98712](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@Wes\_98712](https://community.f5.com/u/Wes_98712)\
**Post date:** [November 9, 2011, 11:26pm UTC](https://community.f5.com/t/header-inserts/57953/15 "2011-11-09T23:26:16Z")

</div>

And another interesting development. If the variable has an \_ in it, for whatever reason ASP doesn’t detect the value. The F5 inserts it in the header as best as I can tell, but the ASP Request.ServerVariable doesn’t pick up the value. This is really odd. I don’t know if this is a bug with the way F5 inserts headers or if it’s an ASP issue.

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [November 10, 2011, 2:53am UTC](https://community.f5.com/t/header-inserts/57953/16 "2011-11-10T02:53:38Z")

</div>

i am not familiar with asp. anyway, would you mind trying this asp code?

Viewing all Server Variables for a Site

[http://weblogs.asp.net/owscott/archive/2010/03/09/viewing-all-server-variables-for-a-site.aspx](http://weblogs.asp.net/owscott/archive/2010/03/09/viewing-all-server-variables-for-a-site.aspx)

---

<div class="post-metadata">

**Author:** ![Wes\_98712](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@Wes\_98712](https://community.f5.com/u/Wes_98712)\
**Post date:** [November 10, 2011, 3:50pm UTC](https://community.f5.com/t/header-inserts/57953/17 "2011-11-10T15:50:23Z")

</div>

If I set it as a String and dump the output it works, which tells me what, it appears to be an encoding issue and not F5. Curious as to why it worked before with a different appliance. But whatever. 😉

---

<div class="post-metadata">

**Author:** ![Kurt\_Knochner\_5](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@Kurt\_Knochner\_5](https://community.f5.com/u/Kurt_Knochner_5)\
**Post date:** [November 11, 2011, 4:37pm UTC](https://community.f5.com/t/header-inserts/57953/18 "2011-11-11T16:37:11Z")

</div>

```tcl
when HTTP_REQUEST {
   if { [HTTP::header "HTTP_SSL_ENV"] equals "On" } {
      log local0. "HEADER HTTPS is: [HTTP::header "HTTP_SSL_ENV"]"
   }
}

```

Maybe I’m a bit confused now, but why are you looking for the header “HTTP\_SSL\_ENV” in the iRule?

The log statements tells me that the HTTP header “HTTP\_SSL\_ENV” was set, not “SSL\_ENV” (see iRule above)!

Nov 9 15:29:36 tmm info tmm[7845]: Rule /Common/test\_irule : HEADER HTTPS is: On

However, you should set the HTTP header to “SSL\_ENV” in the iRule (or profile) on the F5, not “HTTP\_SSL\_ENV”!. ASP is just using a kind of translation machanism to view the HTTP headers as “variables”. They do so by adding HTTP\_ in front of the real HTTP header name.

So, on the F5 please add the header “SSL\_ENV” and in your ASP code look for the variable “HTTP\_SSL\_ENV”. Is this what you tried and still did not see the header value in your ASP code?

BTW: What do you mean by “If I set it as a String and dump the output it works”? Where do you set “it” as a string?

Regards

Kurt Knochner

---

<div class="post-metadata">

**Author:** ![Wes\_98712](https://avatars.discourse-cdn.com/v4/letter/w/5fc32e/32.png) [@Wes\_98712](https://community.f5.com/u/Wes_98712)\
**Post date:** [November 11, 2011, 5:07pm UTC](https://community.f5.com/t/header-inserts/57953/19 "2011-11-11T17:07:12Z")

</div>

Kurt,

I tried that, no dice. If I set it to SSL\_ENV it doesn’t pick it up, in ASP code, but SSLENV does work. In fact I initially thought the issue was with the \_ character because if I set the header to SSL it worked fine, SSL\_ENV doesn’t work but SSLENV does work. I understand the difference on the prepended HTTP\_, but this is something beyond that.

What I mean by string is, in ASPX if I set the server variable as a String variable not varchar or int etc. it displays the entire string HTTP\_SSL\_ENV, if I simply Dim the variable and reference it, it doesn’t display the value. I am not sure if this is an F5 issue or an ASP encoding issue at this point.

---

<div class="post-metadata">

**Author:** ![Michael\_Yates](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@Michael\_Yates](https://community.f5.com/u/Michael_Yates)\
**Post date:** [November 11, 2011, 6:37pm UTC](https://community.f5.com/t/header-inserts/57953/20 "2011-11-11T18:37:56Z")

</div>

Hi Wes,

Take a look at these articles. I believe they may help you narrow down your issue. Especially the first article.

The problem should be clear now. The CGI 1.1 Specification defines a substitution of “-” in Request Header to “\_” in Server Varible names, but what is the substitution of “\_” in Request Headers in Server Variable???

[HOWTO: Retrieve Request Headers using ISAPI, ASP, and ASP.Net](http://blogs.msdn.com/b/david.wang/archive/2006/04/20/howto-retrieve-request-headers-using-isapi-asp-and-asp-net.aspx)

[The WWW Common Gateway Interface Version 1.1](http://www.citycat.ru/doc/CGI/draft/cgi-spec.html)

Hope these help.

[Next page](https://community.f5.com/t/header-inserts/57953.md?page=2)
