From abf5ab340ed76792214ae80c62df7abe0ad1b8a8 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 15 Oct 2019 14:07:10 -0600 Subject: caddyhttp: Improve ResponseRecorder to buffer headers --- modules/caddyhttp/caddyhttp.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'modules/caddyhttp/caddyhttp.go') diff --git a/modules/caddyhttp/caddyhttp.go b/modules/caddyhttp/caddyhttp.go index 5631b30..29a5ab0 100644 --- a/modules/caddyhttp/caddyhttp.go +++ b/modules/caddyhttp/caddyhttp.go @@ -593,6 +593,19 @@ func (ws WeakString) String() string { return string(ws) } +// CopyHeader copies HTTP headers by completely +// replacing dest with src. (This allows deletions +// to be propagated, assuming src started as a +// consistent copy of dest.) +func CopyHeader(dest, src http.Header) { + for field := range dest { + delete(dest, field) + } + for field, val := range src { + dest[field] = val + } +} + // StatusCodeMatches returns true if a real HTTP status code matches // the configured status code, which may be either a real HTTP status // code or an integer representing a class of codes (e.g. 4 for all -- cgit v1.2.3