mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-06 01:08:03 +00:00
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:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user