Added Hijack function to support http.Hijacker
package middleware
import (
+ "bufio"
"bytes"
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
+ "net"
"net/http"
"sort"
"strings"
@@ -116,6 +118,14 @@ func (r *responseDupper) WriteHeader(s int) {
r.ResponseWriter.WriteHeader(s)
}
+// Hijack supports the http.Hijacker interface.
+func (r *responseDupper) Hijack() (net.Conn, *bufio.ReadWriter, error) {
+ if hijacker, ok := r.ResponseWriter.(http.Hijacker); ok {
+ return hijacker.Hijack()
+ }
+ return nil, nil, fmt.Errorf("debug middleware: inner ResponseWriter cannot be hijacked: %T", r.ResponseWriter)
+}
+
// shortID produces a " unique" 6 bytes long string.
// Do not use as a reliable way to get unique IDs, instead use for things like logging.
func shortID() string {
