Skip to content

Commit

Permalink
refine: return error instead of panic when response writer doesn't im…
Browse files Browse the repository at this point in the history
…plement hijacker
  • Loading branch information
xieyuschen committed Aug 7, 2024
1 parent cc4e114 commit 5452a66
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package gin

import (
"bufio"
"errors"
"io"
"net"
"net/http"
Expand Down Expand Up @@ -109,7 +110,11 @@ func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if w.size < 0 {
w.size = 0
}
return w.ResponseWriter.(http.Hijacker).Hijack()
hijacker, ok := w.ResponseWriter.(http.Hijacker)
if !ok {
return nil, nil, errors.New("response writer does not support Hijack`")
}
return hijacker.Hijack()
}

// CloseNotify implements the http.CloseNotifier interface.
Expand Down

0 comments on commit 5452a66

Please sign in to comment.