summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/responsewriter.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/responsewriter.go')
-rw-r--r--modules/caddyhttp/responsewriter.go20
1 files changed, 12 insertions, 8 deletions
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)