Fix X-Ray middleware for http to support http.Hijacker
package xray
import (
+ "bufio"
"fmt"
"net"
"net/http"
@@ -87,6 +88,14 @@ func (s *HTTPSegment) Write(p []byte) (int, error) {
return n, err
}
+// Hijack supports the http.Hijacker interface.
+func (s *HTTPSegment) Hijack() (net.Conn, *bufio.ReadWriter, error) {
+ if hijacker, ok := s.ResponseWriter.(http.Hijacker); ok {
+ return hijacker.Hijack()
+ }
+ return nil, nil, fmt.Errorf("xray: inner ResponseWriter cannot be hijacked: %T", s.ResponseWriter)
+}
+
// recordStatusCode sets Throttle, Fault, Error
//
// It is expected that the mutex has already been locked when calling this method.
