diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-06-14 11:58:28 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-06-14 11:58:28 -0600 |
commit | 5137859e47678aae81e178ca7d164f9e2b4e3121 (patch) | |
tree | f0e5cb9b9a4ad5dc03b53127fcea2a536bd6ee27 /modules/caddyhttp/headers | |
parent | b8e7453fef3dac6036403bc384eec96becff5114 (diff) |
Rename caddy2 -> caddy
Removes the version from the package name
Diffstat (limited to 'modules/caddyhttp/headers')
-rw-r--r-- | modules/caddyhttp/headers/headers.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/modules/caddyhttp/headers/headers.go b/modules/caddyhttp/headers/headers.go index bce5435..84dc453 100644 --- a/modules/caddyhttp/headers/headers.go +++ b/modules/caddyhttp/headers/headers.go @@ -4,12 +4,12 @@ import ( "net/http" "strings" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.middleware.headers", New: func() interface{} { return new(Headers) }, }) @@ -38,7 +38,7 @@ type RespHeaderOps struct { } func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error { - repl := r.Context().Value(caddy2.ReplacerCtxKey).(caddy2.Replacer) + repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer) apply(h.Request, r.Header, repl) if h.Response.Deferred || h.Response.Require != nil { w = &responseWriterWrapper{ @@ -53,7 +53,7 @@ func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt return next.ServeHTTP(w, r) } -func apply(ops *HeaderOps, hdr http.Header, repl caddy2.Replacer) { +func apply(ops *HeaderOps, hdr http.Header, repl caddy.Replacer) { for fieldName, vals := range ops.Add { fieldName = repl.ReplaceAll(fieldName, "") for _, v := range vals { @@ -76,19 +76,12 @@ func apply(ops *HeaderOps, hdr http.Header, repl caddy2.Replacer) { // operations until WriteHeader is called. type responseWriterWrapper struct { *caddyhttp.ResponseWriterWrapper - replacer caddy2.Replacer + replacer caddy.Replacer require *caddyhttp.ResponseMatcher headerOps *HeaderOps wroteHeader bool } -func (rww *responseWriterWrapper) Write(d []byte) (int, error) { - if !rww.wroteHeader { - rww.WriteHeader(http.StatusOK) - } - return rww.ResponseWriterWrapper.Write(d) -} - func (rww *responseWriterWrapper) WriteHeader(status int) { if rww.wroteHeader { return @@ -100,6 +93,13 @@ func (rww *responseWriterWrapper) WriteHeader(status int) { rww.ResponseWriterWrapper.WriteHeader(status) } +func (rww *responseWriterWrapper) Write(d []byte) (int, error) { + if !rww.wroteHeader { + rww.WriteHeader(http.StatusOK) + } + return rww.ResponseWriterWrapper.Write(d) +} + // Interface guards var ( _ caddyhttp.MiddlewareHandler = (*Headers)(nil) |