From 5137859e47678aae81e178ca7d164f9e2b4e3121 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 14 Jun 2019 11:58:28 -0600 Subject: Rename caddy2 -> caddy Removes the version from the package name --- modules/caddyhttp/responsewriter.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'modules/caddyhttp/responsewriter.go') diff --git a/modules/caddyhttp/responsewriter.go b/modules/caddyhttp/responsewriter.go index 4599fd2..3bf3965 100644 --- a/modules/caddyhttp/responsewriter.go +++ b/modules/caddyhttp/responsewriter.go @@ -19,31 +19,31 @@ type ResponseWriterWrapper struct { } // Hijack implements http.Hijacker. It simply calls the underlying -// ResponseWriter's Hijack method if there is one, or returns an error. +// ResponseWriter's Hijack method if there is one, or returns +// ErrNotImplemented otherwise. func (rww *ResponseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) { if hj, ok := rww.ResponseWriter.(http.Hijacker); ok { return hj.Hijack() } - return nil, nil, fmt.Errorf("not a hijacker") + return nil, nil, ErrNotImplemented } // Flush implements http.Flusher. It simply calls the underlying -// ResponseWriter's Flush method if there is one, or panics. +// ResponseWriter's Flush method if there is one. func (rww *ResponseWriterWrapper) Flush() { if f, ok := rww.ResponseWriter.(http.Flusher); ok { f.Flush() - } else { - panic("not a flusher") } } // Push implements http.Pusher. It simply calls the underlying -// ResponseWriter's Push method if there is one, or returns an error. +// ResponseWriter's Push method if there is one, or returns +// ErrNotImplemented otherwise. func (rww *ResponseWriterWrapper) Push(target string, opts *http.PushOptions) error { - if pusher, hasPusher := rww.ResponseWriter.(http.Pusher); hasPusher { + if pusher, ok := rww.ResponseWriter.(http.Pusher); ok { return pusher.Push(target, opts) } - return fmt.Errorf("not a pusher") + return ErrNotImplemented } // HTTPInterfaces mix all the interfaces that middleware ResponseWriters need to support. @@ -54,5 +54,9 @@ type HTTPInterfaces interface { http.Hijacker } +// ErrNotImplemented is returned when an underlying +// ResponseWriter does not implement the required method. +var ErrNotImplemented = fmt.Errorf("method not implemented") + // Interface guards var _ HTTPInterfaces = (*ResponseWriterWrapper)(nil) -- cgit v1.2.3