@@ -105,13 +105,6 @@ func accept(w http.ResponseWriter, r *http.Request, opts *AcceptOptions) (_ *Con
105105 }
106106 }
107107
108- hj , ok := w .(http.Hijacker )
109- if ! ok {
110- err = errors .New ("http.ResponseWriter does not implement http.Hijacker" )
111- http .Error (w , http .StatusText (http .StatusNotImplemented ), http .StatusNotImplemented )
112- return nil , err
113- }
114-
115108 w .Header ().Set ("Upgrade" , "websocket" )
116109 w .Header ().Set ("Connection" , "Upgrade" )
117110
@@ -136,10 +129,14 @@ func accept(w http.ResponseWriter, r *http.Request, opts *AcceptOptions) (_ *Con
136129 ginWriter .WriteHeaderNow ()
137130 }
138131
139- netConn , brw , err := hj . Hijack ( )
132+ netConn , brw , err := hijack ( w )
140133 if err != nil {
141- err = fmt .Errorf ("failed to hijack connection: %w" , err )
142- http .Error (w , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
134+ if errors .Is (err , errHTTPHijackNotSupported ) {
135+ http .Error (w , http .StatusText (http .StatusNotImplemented ), http .StatusNotImplemented )
136+ } else {
137+ err = fmt .Errorf ("failed to hijack connection: %w" , err )
138+ http .Error (w , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
139+ }
143140 return nil , err
144141 }
145142
0 commit comments