Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add X-FORWARDED-HOST header insert irule #264

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading