Merge pull request #1971 from weaveworks/mike/errorhandler/implement-hijack

middleware/errorhandler: Implement Hijacker so it works with ws proxy
This commit is contained in:
Mike Lang
2016-11-10 14:39:06 -08:00
committed by GitHub
2 changed files with 15 additions and 1 deletions

View File

@@ -1,6 +1,9 @@
package middleware
import (
"bufio"
"fmt"
"net"
"net/http"
)
@@ -78,3 +81,14 @@ func (i *errorInterceptor) Write(data []byte) (int, error) {
}
return len(data), nil
}
// errorInterceptor also implements net.Hijacker, to let the downstream Handler
// hijack the connection. This is needed, for example, for working with websockets.
func (i *errorInterceptor) Hijack() (net.Conn, *bufio.ReadWriter, error) {
hj, ok := i.originalWriter.(http.Hijacker)
if !ok {
return nil, nil, fmt.Errorf("error interceptor: can't cast original ResponseWriter to Hijacker")
}
i.gotCode = true
return hj.Hijack()
}

View File

@@ -45,7 +45,7 @@ var LogFailed = Log{
// want to report on success, i.e. http.StatusOK.
//
// interceptor also implements net.Hijacker, to let the downstream Handler
// hijack the connection. This is needed by the app-mapper's proxy.
// hijack the connection. This is needed, for example, for working with websockets.
type interceptor struct {
http.ResponseWriter
statusCode int