Skip to content

Commit 81831dd

Browse files
refactor http-response rules addition
1 parent a9d86d1 commit 81831dd

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

manifests/haproxy/autoload.pp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,32 @@
8383
}
8484

8585
$http_edge_rules_all = Hash($http_edge_rules_all_placeholder)
86+
# Filter undef fields from the http-edge rules
8687
$http_edge_rules_all_real_without_undef = $http_edge_rules_all.map |$key, $value| {
8788
$real_rules = $value.filter |$rules| { $rules =~ NotUndef }
8889
[$key, $real_rules]
8990
}
9091
$http_edge_rules_all_real = Hash($http_edge_rules_all_real_without_undef)
9192

93+
# Insert additional http-edge rules that are service specific
9294
if 'canonicals' in $http_edge_services or 'status410' in $http_edge_services {
93-
$http_response_rules = $ducktape::haproxy::frontends[$http_edge_frontend]['options']['http-response']
9495
if 'canonicals' in $http_edge_services {
9596
$http_edge_canonicals_rules_real = flatten($http_edge_rules_all_real['canonicals'], 'set-var(txn.canonical_custom) hdr(X-Canonical-Custom) if { hdr(X-Canonical-Custom) -m found }', 'del-header X-Canonical-Custom if { hdr(X-Canonical-Custom) -m found }')
96-
$http_response_canonicals_rules_real = concat($http_response_rules, 'set-header link %[var(txn.canonical_custom)] if { var(txn.canonical_custom) -m found }')
97-
}
98-
if 'status410' in $http_edge_services {
99-
$http_response_status410_rules_real = concat($http_response_rules, 'set-status 410 if { var(txn.status410) -m bool }')
10097
}
101-
if 'canonicals' in $http_edge_services and 'status410' in $http_edge_services {
102-
$http_response_rules_real_placeholder = concat($http_response_canonicals_rules_real, $http_response_status410_rules_real)
103-
$http_response_rules_real = unique($http_response_rules_real_placeholder)
104-
} elsif 'canonicals' in $http_edge_services {
105-
$http_response_rules_real = $http_response_canonicals_rules_real
106-
} else {
107-
$http_response_rules_real = $http_response_status410_rules_real
98+
$http_response_rules = $ducktape::haproxy::frontends[$http_edge_frontend]['options']['http-response']
99+
$http_response_new_rules = $http_edge_services.map | $service | {
100+
if $service == 'canonicals' {
101+
'set-header link %[var(txn.canonical_custom)] if { var(txn.canonical_custom) -m found }'
102+
} elsif $service == 'canonicals' {
103+
'set-status 410 if { var(txn.status410) -m bool }'
104+
}
108105
}
106+
$http_response_new_rules_real = $http_response_rules.filter |$rules| { $rules =~ NotUndef }
107+
$http_response_rules_real = concat($http_response_rules, $http_response_new_rules_real)
109108
$http_response_rules_hash = {$http_edge_frontend => {'options' => {'http-response' => $http_response_rules_real}}}
110109
}
111110

112-
# Insert http-edge redirect rules at the marker position, or at the end if no marker
111+
# Insert http-edge rules at the marker position, or at the end if no marker
113112
$http_request_rules = $ducktape::haproxy::frontends[$http_edge_frontend]['options']['http-request']
114113
if 'redirects' in $http_edge_services and grep($http_request_rules, $http_edge_markers['redirects']) == [] {
115114
$http_request_rules_with_redirects = concat($http_request_rules, $http_edge_rules_all_real['redirects'])

0 commit comments

Comments
 (0)