Skip to content

Commit

Permalink
add xfh header insert
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Kratochvil committed Apr 9, 2024
1 parent 340884e commit 33e5a5f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions octavia_f5/restclient/as3objects/irule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 33e5a5f

Please sign in to comment.