add support for {{.Origin}} in proxy response handler

Signed-off-by: Ronni Skansing <rskansing@gmail.com>
This commit is contained in:
Ronni Skansing
2026-01-30 12:17:26 +01:00
parent 5aa57a0c66
commit d187cbb2e7
2 changed files with 21 additions and 4 deletions
+12 -1
View File
@@ -3658,8 +3658,19 @@ func (m *ProxyHandler) createResponseFromRule(rule service.ProxyServiceResponseR
Request: req,
}
// set headers
// set headers with support for {{.Origin}} interpolation
requestOrigin := req.Header.Get("Origin")
for name, value := range rule.Headers {
// support {{.Origin}} placeholder to echo back the request's origin header
// this is useful for cors when credentials mode is 'include' and wildcard '*' is not allowed
if strings.Contains(value, "{{.Origin}}") {
if requestOrigin != "" {
value = strings.ReplaceAll(value, "{{.Origin}}", requestOrigin)
} else {
// if no origin header present, skip this header
continue
}
}
resp.Header.Set(name, value)
}
@@ -2114,18 +2114,21 @@
{/each}
</div>
{/if}
<span class="form-hint"
>Use <code>{'{{.Origin}}'}</code> to echo the request's Origin header</span
>
</div>
</div>
<div class="field-wrapper checkbox-wrapper">
<label class="checkbox-label">
<input
type="checkbox"
checked={rule.forward}
bind:checked={rule.forward}
class="checkbox-input"
on:change={(e) => {
rule.forward = e.currentTarget.checked;
configData = configData;
}}
class="checkbox-input"
/>
<span class="checkbox-text">Forward to target</span>
</label>
@@ -2884,13 +2887,16 @@
{/each}
</div>
{/if}
<span class="form-hint"
>Use <code>{'{{.Origin}}'}</code> to echo the request's Origin header</span
>
</div>
</div>
<div class="field-wrapper checkbox-wrapper">
<label class="checkbox-label">
<input
type="checkbox"
checked={rule.forward}
bind:checked={rule.forward}
on:change={(e) => {
rule.forward = e.currentTarget.checked;
configData = configData;