mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Merge pull request #1642 from tw4452852/internal
internal: inherit original ResponseWriter's interfaces
This commit is contained in:
commit
5685a16449
1 changed files with 50 additions and 0 deletions
|
@ -7,6 +7,8 @@
|
||||||
package internalsrv
|
package internalsrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/mholt/caddy/caddyhttp/httpserver"
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
||||||
|
@ -94,3 +96,51 @@ func (w internalResponseWriter) Write(b []byte) (int, error) {
|
||||||
}
|
}
|
||||||
return w.ResponseWriter.Write(b)
|
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{}
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue