Forum Discussion
Nov 21, 2014
BIG-IP : irule : add request header ( replace if exists )
F5 BIG-IP Virtual Edition v11.4.1 (Build 635.0) LTM on ESXi
I need to add/replace a specific request header. Here's my iRule :
when HTTP_REQUEST {
if { [HTTP::header exists "original-uri"] } ...
nitass_89166
Nov 21, 2014Noctilucent
Is there a way to perform the insert/replace in a single line ?
can't you just remove (HTTP::header remove) and then insert (HTTP::header insert)?
- Nov 21, 2014for case where header is not present : would [HTTP::header remove] throw an error ?
- nitass_89166Nov 21, 2014Noctilucentno
- Nov 21, 2014so why does [HTTP::header replace] command exist ?
- nitass_89166Nov 21, 2014Noctilucenti usually use HTTP::header remove to make sure all is removed. HTTP::header replace will replace only the last one. Replaces the value of the last occurrence of the header named with the string . This command performs a header insertion if the header was not present. If there are multiple instances of the header, only the last instance is replaced. HTTP::header https://clouddocs.f5.com/api/irules/HTTP__header.html
- Nov 21, 2014what are some scenarios where same header could be twice added to a request ? i can imagine a scenario where a virtual-server has multiple irules that add the same header without performing checks
- shaggyNov 21, 2014Nimbostratusx-forwarded-for headers are often added by devices between a client and destionation, and those devices can behave differently. some append to the current header value, some prepend, some add another header altogether...there's no one-size-fits-all. if original-uri only exists once in your app's requests (and you know it only exists once), replace alone should do the trick
- Nov 24, 2014thanks shaggy. in my case, the original-uri header is added by a high-priority i-rule on my virtual-server - so the only way multiple original-uri headers could be added is on redirects -- and that's only if i didn't include a pre-exists check -- so it seems replace is the best option for my user-case
- Nov 24, 2014thanks shaggy. in my case, the original-uri header is added by a high-priority i-rule on my virtual-server - so the only way multiple original-uri headers could be added is on redirects -- and that's only if i didn't include a pre-exists check -- so it seems replace is the best option for my user-case
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