I’m attempting to insert [HTTP::host] into any inbound requests where the HTTP::header host field is missing, but it doesn’t appear to be working.
Straight-forward irule:
when HTTP_REQUEST {
if { [HTTP::header exists “HOST”]} {
} else {
HTTP::header replace HOST [HTTP::host]
}
}
It appears that the host header is being added, but blank:
GET /includes HTTP/1.1
Content-Length: 2
HOST:
Any idea what I’m missing?
HTTP::host returns the value of the Host header. There’s no value, so there’s nothing to insert in your rule above.
There’s a bit more on HTTP::host here, including a couple of examples:
http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP__host.html
RFC2616 (covering HTTP/1.1) says that if no host is given in the URI (as in your example output above), the Host header should be blank:
A client MUST include a Host header field in all HTTP/1.1 request
messages . If the requested URI does not include an Internet host
name for the service being requested, then the Host header field MUST
be given with an empty value. An HTTP/1.1 proxy MUST ensure that any
request message it forwards does contain an appropriate Host header
field that identifies the service being requested by the proxy. All
Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request)
status code to any HTTP/1.1 request message which lacks a Host header
field.
So what you’ve got there is actually a legal request, even if it’s not what you’re looking for (which may be only a small comfort).
If you need to strip the host out of an absolute URL (see HTTP::uri) , you can probably do it and then stuff that into a Host header.