Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit bf4093c

Browse files
authored
feat: add header_up support (#22)
1 parent cf07378 commit bf4093c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

internal/caddy/caddy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func appendRule(builder *strings.Builder, rule config.Rule, port int) {
7474
builder.WriteString(fmt.Sprintf(" tls {\n %s\n }\n", newTls))
7575
}
7676

77+
// Add header_up directives
78+
for _, header := range rule.HeaderUp {
79+
builder.WriteString(fmt.Sprintf(" header_up %s %s\n", header.Name, header.Value))
80+
}
81+
7782
for _, handle := range rule.Handle {
7883
builder.WriteString(fmt.Sprintf(" handle %s {\n", handle.Path))
7984
for _, directive := range handle.Directives {

internal/caddy/caddy_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ func TestConvertToCaddyfile(t *testing.T) {
4343
To: "http://localhost:{port}",
4444
},
4545
},
46+
HeaderUp: []config.HeaderUp{
47+
{
48+
Name: "X-Real-IP",
49+
Value: "{http.request.remote.host}",
50+
},
51+
},
4652
},
4753
},
4854
}
4955

5056
caddyfile := ConvertToCaddyfile(caddyCfg, 8080)
51-
expectedCaddyfile := "{\n email test@example.com\n on_demand_tls {\n ask https://acme.example.com/directory\n interval 3600\n burst 13\n }\n}\n\nlocalhost {\n tls {\n internal\n }\n handle / {\n root * /usr/share/caddy\n }\n handle /healthz {\n respond \"OK\" 200\n }\n reverse_proxy / http://localhost:8080\n}\n\n"
57+
expectedCaddyfile := "{\n email test@example.com\n on_demand_tls {\n ask https://acme.example.com/directory\n interval 3600\n burst 13\n }\n}\n\nlocalhost {\n tls {\n internal\n }\n header_up X-Real-IP {http.request.remote.host}\n handle / {\n root * /usr/share/caddy\n }\n handle /healthz {\n respond \"OK\" 200\n }\n reverse_proxy / http://localhost:8080\n}\n\n"
5258
assert.Equal(t, expectedCaddyfile, caddyfile)
5359
}
5460

internal/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ type Handle struct {
4141
Directives []string `yaml:"directives"`
4242
}
4343

44+
type HeaderUp struct {
45+
Name string `yaml:"name"`
46+
Value string `yaml:"value"`
47+
}
48+
4449
type Rule struct {
4550
Match string `yaml:"match"`
4651
Tls string `yaml:"tls"`
4752
ReverseProxy []ReverseProxy `yaml:"reverse_proxy"`
4853
Handle []Handle `yaml:"handle"`
54+
HeaderUp []HeaderUp `yaml:"header_up"`
4955
}
5056

5157
type OnDemandTlsConfig struct {

0 commit comments

Comments
 (0)