-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocket: should compare 'Upgrade' header value with case insensitive #4617
WebSocket: should compare 'Upgrade' header value with case insensitive #4617
Conversation
858af90
to
c2109db
Compare
RFC 6445, section 4.2.1 says clearly: "An Upgrade header field containing the value "websocket", treated as an ASCII case-insensitive value". https://tools.ietf.org/html/rfc6455#section-4.2.1 And now, we have `String#compare(other, case_insensitive: true)`.
c2109db
to
40bb277
Compare
@@ -14,7 +14,7 @@ class HTTP::WebSocketHandler | |||
end | |||
|
|||
def call(context) | |||
if context.request.headers["Upgrade"]? == "websocket" && context.request.headers.includes_word?("Connection", "Upgrade") | |||
if context.request.headers["Upgrade"]?.try(&.compare("websocket", case_insensitive: true)) == 0 && context.request.headers.includes_word?("Connection", "Upgrade") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now a very long line of code, it might be good to refactor out upgrade_header = context.request.headers["Upgrade"]?
and use if upgrade_header && upgrade_header.compare("websocket", case_insensitive: true) == 0 && context.request.headers.includes_word?("Connection", "Upgrade")
but that's still rather long.
How about structuring this as a series of guards:
call_next(context) unless upgrade_header && upgrade_header.compare("websocket", case_insensitive: true) == 0
call_next(context) unless context.request.headers.includes_word?("Connection", "Upgrade")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 😆
One of the Kemal users exactly reported an issue related to this. I think this is an important issue and this PR solves 👍 |
IE11 and below are sending 'Upgrade' header with capitalized "Websocket" |
Any ETA for merging this? |
How about now? :) |
Thanks @makenowjust! Love this little, self-contained PRs with specs ❤️ |
crystal-lang#4617) RFC 6445, section 4.2.1 says clearly: "An Upgrade header field containing the value "websocket", treated as an ASCII case-insensitive value". https://tools.ietf.org/html/rfc6455#section-4.2.1 And now, we have `String#compare(other, case_insensitive: true)`.
RFC 6445, section 4.2.1 says clearly:
And now, we have
String#compare(other, case_insensitive: true)
.