-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
http.ResponseController
instead of http.Hijacker
assertion
Fixes #455
- Loading branch information
Showing
3 changed files
with
47 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//go:build go1.20 | ||
|
||
package websocket | ||
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"net" | ||
"net/http" | ||
) | ||
|
||
var errHTTPHijackNotSupported = errors.New("http.ResponseWriter does not implement http.Hijacker") | ||
Check failure on line 12 in hijack.go GitHub Actions / lint
|
||
|
||
func hijack(w http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error) { | ||
Check failure on line 14 in hijack.go GitHub Actions / lint
|
||
conn, rw, err := http.NewResponseController(w).Hijack() | ||
if errors.Is(err, http.ErrNotSupported) { | ||
return nil, nil, errHTTPHijackNotSupported | ||
} | ||
return conn, rw, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//go:build !go1.20 | ||
|
||
package websocket | ||
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"net" | ||
"net/http" | ||
) | ||
|
||
var errHTTPHijackNotSupported = errors.New("http.ResponseWriter does not implement http.Hijacker") | ||
|
||
func hijack(w http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error) { | ||
hj, ok := w.(http.Hijacker) | ||
if !ok { | ||
return nil, nil, errHTTPHijackNotSupported | ||
} | ||
return hj.Hijack() | ||
} |