Web / Caddy Server Interview questions
What is the purpose of the header directive?
header adds, sets, or removes HTTP headers on requests or responses passing through a site block, which is useful for security headers, caching hints, and CORS.
example.com { header { Strict-Transport-Security "max-age=31536000" X-Content-Type-Options "nosniff" -Server } reverse_proxy localhost:3000 }
Inside the block, a header name followed by a value sets it (overwriting any existing value), a plus prefix like +Vary appends instead of replacing, and a minus prefix like -Server deletes the header entirely. Header directives can also be scoped to responses only, using header for downstream response headers and request_header for upstream requests in a reverse proxy.
More Related questions...