mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Improve websocket match logic. Fixes #401
This commit is contained in:
parent
e07be72dcf
commit
00981bcf44
2 changed files with 24 additions and 1 deletions
|
@ -11,7 +11,7 @@ module Kemal
|
|||
end
|
||||
|
||||
def call(context : HTTP::Server::Context)
|
||||
return call_next(context) unless context.ws_route_defined?
|
||||
return call_next(context) unless context.ws_route_defined? && websocket_upgrade_request?(context)
|
||||
context.request.url_params ||= context.ws_route_lookup.params
|
||||
content = context.websocket.call(context)
|
||||
context.response.print(content)
|
||||
|
@ -34,5 +34,12 @@ module Kemal
|
|||
private def radix_path(method, path)
|
||||
"/#{method.downcase}#{path}"
|
||||
end
|
||||
|
||||
private def websocket_upgrade_request?(context)
|
||||
return false unless upgrade = context.request.headers["Upgrade"]?
|
||||
return false unless upgrade.compare("websocket", case_insensitive: true) == 0
|
||||
|
||||
context.request.headers.includes_word?("Connection", "Upgrade")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue