vhost: Add option to find and replace headers in reverse proxy

This commit is contained in:
uumas
2026-03-11 22:13:29 +02:00
parent 080c5b4dc2
commit 3013d3edf0
4 changed files with 83 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ vhost_web_server: caddy
vhost_locations: []
vhost_headers: {}
vhost_find_replace_headers: []
vhost_delete_headers: []
vhost_basicauth: false

View File

@@ -46,6 +46,25 @@ argument_specs:
type: dict
required: false
default: {}
vhost_find_replace_headers:
description: Response headers to find and replace
type: list
elements: dict
required: false
default: []
options:
header:
description: Header to modify
type: str
required: true
find:
description: Header content to find
type: str
required: true
replace:
description: Content to replace matching headers with
type: str
required: true
vhost_delete_headers:
description: List of reponse headers to delete
type: list
@@ -242,6 +261,25 @@ argument_specs:
type: dict
required: false
default: "{{ vhost_headers }}"
find_replace_headers:
description: Response headers to find and replace
type: list
elements: dict
required: false
default: "{{ vhost_find_replace_headers }}"
options:
header:
description: Header to modify
type: str
required: true
find:
description: Header content to find
type: str
required: true
replace:
description: Content to replace matching headers with
type: str
required: true
delete_headers:
description: List of response headers to delete
type: list
@@ -414,6 +452,25 @@ argument_specs:
type: dict
required: false
default: "{{ vhost_headers }}"
find_replace_headers:
description: Response headers to find and replace
type: list
elements: dict
required: false
default: "{{ vhost_find_replace_headers }}"
options:
header:
description: Header to modify
type: str
required: true
find:
description: Header content to find
type: str
required: true
replace:
description: Content to replace matching headers with
type: str
required: true
delete_headers:
description: List of response headers to delete
type: list
@@ -610,6 +667,24 @@ argument_specs:
description: Dict of response headers and their values
type: dict
required: false
find_replace_headers:
description: Response headers to find and replace
type: list
elements: dict
required: false
options:
header:
description: Header to modify
type: str
required: true
find:
description: Header content to find
type: str
required: true
replace:
description: Content to replace matching headers with
type: str
required: true
delete_headers:
description: List of response headers to delete
type: list

View File

@@ -22,6 +22,12 @@
{% for header in matcher.delete_headers %}
header -{{ header }}
{% endfor %}
{% for header in matcher.find_replace_headers %}
header {
{{ header.header }} `^{{ header.find }}$` `{{ header.replace }}`
defer
}
{% endfor %}
{% for header in matcher.headers | dict2items %}
header {{ header.key }} `{{ header.value }}`
{% endfor %}

View File

@@ -13,6 +13,7 @@ _vhost_matchers: >-
_vhost_location_defaults:
type: "{{ vhost_type }}"
headers: "{{ vhost_headers }}"
find_replace_headers: "{{ vhost_find_replace_headers }}"
delete_headers: "{{ vhost_delete_headers }}"
basicauth: "{{ vhost_basicauth }}"