Commit 5685a164 authored by Matt Holt's avatar Matt Holt Committed by GitHub

Merge pull request #1642 from tw4452852/internal

internal: inherit original ResponseWriter's interfaces
parents e0ed7093 f58653bc
......@@ -7,6 +7,8 @@
package internalsrv
import (
"bufio"
"net"
"net/http"
"github.com/mholt/caddy/caddyhttp/httpserver"
......@@ -94,3 +96,51 @@ func (w internalResponseWriter) Write(b []byte) (int, error) {
}
return w.ResponseWriter.Write(b)
}
// Hijack implements http.Hijacker. It simply wraps the underlying
// ResponseWriter's Hijack method if there is one, or returns an error.
func (w internalResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if hj, ok := w.ResponseWriter.(http.Hijacker); ok {
return hj.Hijack()
}
return nil, nil, httpserver.NonHijackerError{Underlying: w.ResponseWriter}
}
// Flush implements http.Flusher. It simply wraps the underlying
// ResponseWriter's Flush method if there is one, or panics.
func (w internalResponseWriter) Flush() {
if f, ok := w.ResponseWriter.(http.Flusher); ok {
f.Flush()
} else {
panic(httpserver.NonFlusherError{Underlying: w.ResponseWriter})
}
}
// CloseNotify implements http.CloseNotifier.
// It just inherits the underlying ResponseWriter's CloseNotify method.
// It panics if the underlying ResponseWriter is not a CloseNotifier.
func (w internalResponseWriter) CloseNotify() <-chan bool {
if cn, ok := w.ResponseWriter.(http.CloseNotifier); ok {
return cn.CloseNotify()
}
panic(httpserver.NonCloseNotifierError{Underlying: w.ResponseWriter})
}
// Push implements http.Pusher.
// It just inherits the underlying ResponseWriter's Push method.
// It panics if the underlying ResponseWriter is not a Pusher.
func (w internalResponseWriter) Push(target string, opts *http.PushOptions) error {
if pusher, hasPusher := w.ResponseWriter.(http.Pusher); hasPusher {
return pusher.Push(target, opts)
}
return httpserver.NonPusherError{Underlying: w.ResponseWriter}
}
// Interface guards
var (
_ http.Pusher = internalResponseWriter{}
_ http.Flusher = internalResponseWriter{}
_ http.CloseNotifier = internalResponseWriter{}
_ http.Hijacker = internalResponseWriter{}
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment