Modify request header

1. Caddy version (caddy version):

v2

2. How I run Caddy:

/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile

a. System environment:

Amazon Linux2

3. The problem I’m having:

I have next setup:

Caddy → Varnish → Nginx

As caddy cant brotli on-fly but Varnish can store brotli as separate hash i want to modify Accept-Encoding next way:

If Accept-Encoding ~ “br”, then header_up Accept-Encoding “br”
if Accept-Encoding ~ “gzip”, then header_up Accept-Encoding “gzip”
Else header_up Accept-Encoding “*”

And nginx will compress based on Accept-Encoding header, Varnish will cache separately and Caddy will response the way clear for the client.

Is there an option to “if” for header_up based on request header value?

Thanks.

You can use the map directive for this!

map {header.Accept-Encoding} {accept} {
	~br      br
	~gzip    gzip
	default  *
}

...

reverse_proxy <addr> {
	header_up Accept-Encoding {accept}
}
1 Like

Yup, thats it! Thanks a lot!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.