From 33e5a5fef7357e0965483f334d69dfeccd8b3785 Mon Sep 17 00:00:00 2001 From: Michal Kratochvil Date: Tue, 9 Apr 2024 08:36:53 +0000 Subject: [PATCH] add xfh header insert --- octavia_f5/restclient/as3objects/irule.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/octavia_f5/restclient/as3objects/irule.py b/octavia_f5/restclient/as3objects/irule.py index b34f19d9..1e0a9bbd 100644 --- a/octavia_f5/restclient/as3objects/irule.py +++ b/octavia_f5/restclient/as3objects/irule.py @@ -22,6 +22,13 @@ when SERVER_CONNECTED { TCP::respond $proxyheader }""" +X_FORWARDED_HOST = """when HTTP_REQUEST priority 500 { + if { [HTTP::has_responded] }{ return } + if { [HTTP::header exists {X-Forwarded-Host}] } { + HTTP::header remove {X-Forwarded-Host} + HTTP::header insert {X-Forwarded-Host} [HTTP::host] + } +}""" X_FORWARDED_FOR = """when HTTP_REQUEST { if { [HTTP::has_responded] }{ return } HTTP::header insert "X-Forwarded-For" [getfield [IP::remote_addr] "%" 1] @@ -168,6 +175,11 @@ def get_header_irules(insert_headers): # Entities is a list of tuples, which each describe AS3 objects # which may reference each other but do not form a hierarchy. entities = [] + if insert_headers.get('X-Forwarded-Host', False): + irule = IRule(X_FORWARDED_HOST, + remark="Insert X-Forwarded-Host Header") + entities.append(('irule_x_forwarded_host', irule)) + if insert_headers.get('X-Forwarded-For', False): irule = IRule(X_FORWARDED_FOR, remark="Insert X-Forwarded-For Header")