Forum Discussion
James_Thomson
Employee
Feb 02, 2015How can I reorder HTTP headers?
I want to insert an HTTP header into the current list of HTTP headers, but I need it to be the first HTTP header in the list, before the Host, Content-Type and Content-Length. Using the standard HTTP...
StephanManthey
Nacreous
Feb 02, 2015Hi James,
you can give this one a try (perhaps you want to apply in HTTP_RESPONSE context), please.
when HTTP_REQUEST {
initialize array to store all headers
array set header_list { }
parse each header and store in array
foreach header_name [HTTP::header names] {
set header_list($header_name) [HTTP::header $header_name]
log local0. "name: $header_name; value: $header_list($header_name)"
}
delete all headers
foreach header_name [HTTP::header names] {
HTTP::header remove $header_name
log local0. "header removed: $header_name"
}
insert new custom header
HTTP::header insert MyNewTestHeader MyNewTestHeaderValue
insert all headers from array (append)
foreach header_name [array names header_list] {
HTTP::header insert $header_name $header_list($header_name)
log local0. "header inserted: $header_name; value: $header_list($header_name)"
}
}
Be careful with cookies, there may be multiple header instances and the code above does not really care about it.
Thanks, Stephan
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects