-
Notifications
You must be signed in to change notification settings - Fork 276
Closed
Labels
Description
Describe the bug
The compress handler leaves an empty http.Hijacker interface in the wrapped response writer even when the incoming response writer does not implement http.Hijacker. This causes the wrapped response writer to still implement http.Hijacker, but if you try to call Hijack() it will panic.
Steps to Reproduce
type myWriter struct {
http.ResponseWriter
}
func main() {
http.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
if h, ok := w.(http.Hijacker); ok {
h.Hijack()
}
})
myMiddleware := func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.ServeHTTP(&myWriter{w}, r)
})
}
handler := myMiddleware(handlers.CompressHandler(http.DefaultServeMux))
go func() {
log.Panic(http.ListenAndServe("127.0.0.1:1337", handler))
}()
time.Sleep(1 * time.Second)
http.Get("http://127.0.0.1:1337/test")
}Reactions are currently unavailable