mirror of
https://github.com/caddyserver/caddy.git
synced 2026-04-19 17:30:16 +00:00
reverseproxy: add option to omit Via header in proxied responses
This commit is contained in:
parent
8e2dd5079c
commit
2acebdbcaa
2 changed files with 20 additions and 4 deletions
|
|
@ -100,6 +100,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
|
|||
// stream_timeout <duration>
|
||||
// stream_close_delay <duration>
|
||||
// verbose_logs
|
||||
// omit_via_header
|
||||
//
|
||||
// # request manipulation
|
||||
// trusted_proxies [private_ranges] <ranges...>
|
||||
|
|
@ -863,6 +864,12 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
|||
}
|
||||
h.VerboseLogs = true
|
||||
|
||||
case "omit_via_header":
|
||||
if h.OmitViaHeader {
|
||||
return d.Err("omit_via_header already specified")
|
||||
}
|
||||
h.OmitViaHeader = true
|
||||
|
||||
default:
|
||||
return d.Errf("unrecognized subdirective %s", d.Val())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,6 +220,13 @@ type Handler struct {
|
|||
// EXPERIMENTAL: This feature is subject to change or removal.
|
||||
VerboseLogs bool `json:"verbose_logs,omitempty"`
|
||||
|
||||
// If true, omit the Via header on proxied responses sent to the client.
|
||||
//
|
||||
// Per RFC 9110, proxies MUST add Via to forwarded messages.
|
||||
// However, an HTTP-to-HTTP gateway MAY omit Via on response messages.
|
||||
// This option controls that response behavior.
|
||||
OmitViaHeader bool `json:"omit_via_header,omitempty"`
|
||||
|
||||
Transport http.RoundTripper `json:"-"`
|
||||
CB CircuitBreaker `json:"-"`
|
||||
DynamicUpstreams UpstreamSource `json:"-"`
|
||||
|
|
@ -1153,11 +1160,13 @@ func (h *Handler) finalizeResponse(
|
|||
|
||||
// delete our Server header and use Via instead (see #6275)
|
||||
rw.Header().Del("Server")
|
||||
var protoPrefix string
|
||||
if !strings.HasPrefix(strings.ToUpper(res.Proto), "HTTP/") {
|
||||
protoPrefix = res.Proto[:strings.Index(res.Proto, "/")+1]
|
||||
if !h.OmitViaHeader {
|
||||
var protoPrefix string
|
||||
if !strings.HasPrefix(strings.ToUpper(res.Proto), "HTTP/") {
|
||||
protoPrefix = res.Proto[:strings.Index(res.Proto, "/")+1]
|
||||
}
|
||||
rw.Header().Add("Via", fmt.Sprintf("%s%d.%d Caddy", protoPrefix, res.ProtoMajor, res.ProtoMinor))
|
||||
}
|
||||
rw.Header().Add("Via", fmt.Sprintf("%s%d.%d Caddy", protoPrefix, res.ProtoMajor, res.ProtoMinor))
|
||||
|
||||
// apply any response header operations
|
||||
if h.Headers != nil && h.Headers.Response != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue