Enhance WebSocket upgrade detection in Mihomo
- Updated the `isWebSocketUpgrade` function to improve handling of WebSocket upgrade requests by considering the presence of the "Sec-WebSocket-Key" header as a strong indicator. - Added a new test case in `TestIsWebSocketUpgrade` to validate the detection logic for requests with the "Sec-WebSocket-Key" header, ensuring comprehensive test coverage.
This commit is contained in:
@@ -53,4 +53,10 @@ func TestIsWebSocketUpgrade(t *testing.T) {
|
||||
if isWebSocketUpgrade(r2) {
|
||||
t.Fatal("expected non-websocket when Connection lacks upgrade")
|
||||
}
|
||||
|
||||
r3 := httptest.NewRequest(http.MethodGet, "http://gw/api/mtg/mihomo/traffic", nil)
|
||||
r3.Header.Set("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==")
|
||||
if !isWebSocketUpgrade(r3) {
|
||||
t.Fatal("expected websocket upgrade when Sec-WebSocket-Key is present")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user