fasthttp / websocket

WebSocket implementation for fasthttp.
BSD 2-Clause "Simplified" License
540 stars 55 forks source link

Case caused FastHTTPIsWebSocketUpgrade prediction false. #28

Closed leopku closed 2 years ago

leopku commented 2 years ago

My client was mastodon(a decentralized social media like twitter) web and native apps. My server was powered by fiber and websocket component was offical websocket middleware of fiber based on this amazing library.

The issue was websocket upgrade prediction websocket.IsWebSocketUpgrade(ctx) was always false.

I checked the request and dig into the source code, and found: ws client sent request header with Upgrade: websocket, but the server side only return true when the value was Websocket.

Does it should convert the value of Upgrade header to same case before checking?

https://github.com/fasthttp/websocket/blob/c48d95b9f1b2dfaf28be1c828e7008a77da1dbba/server_fasthttp.go#L227

// FastHTTPIsWebSocketUpgrade returns true if the client requested upgrade to the
// WebSocket protocol.
func FastHTTPIsWebSocketUpgrade(ctx *fasthttp.RequestCtx) bool {
    return tokenContainsValue(strconv.B2S(ctx.Request.Header.Peek("Connection")), "Upgrade") &&
        tokenContainsValue(strconv.B2S(ctx.Request.Header.Peek("Upgrade")), "Websocket")
}