Don't raise on WS route not found
This commit is contained in:
parent
2b604dfb30
commit
3fd3349383
3 changed files with 21 additions and 7 deletions
|
@ -1,6 +1,19 @@
|
|||
require "./spec_helper"
|
||||
|
||||
describe "Kemal::WebSocketHandler" do
|
||||
it "doesn't match on wrong route" do
|
||||
handler = Kemal::WebSocketHandler.new "/" { }
|
||||
headers = HTTP::Headers{
|
||||
"Upgrade" => "websocket",
|
||||
"Connection" => "Upgrade",
|
||||
"Sec-WebSocket-Key" => "dGhlIHNhbXBsZSBub25jZQ==",
|
||||
}
|
||||
request = HTTP::Request.new("GET", "/asd", headers)
|
||||
io_with_context = create_request_and_return_io(handler, request)
|
||||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
client_response.status_code.should eq(404)
|
||||
end
|
||||
|
||||
it "matches on given route" do
|
||||
handler = Kemal::WebSocketHandler.new "/" { }
|
||||
headers = HTTP::Headers{
|
||||
|
|
|
@ -13,12 +13,13 @@ class HTTP::Server
|
|||
end
|
||||
|
||||
def params
|
||||
websocket? = @request.headers.has_key?("Upgrade")
|
||||
@request.url_params ||= unless websocket?
|
||||
route_lookup.params
|
||||
else
|
||||
ws_route_lookup.params
|
||||
end
|
||||
connection_type = @request.headers.fetch("Connection", nil)
|
||||
@request.url_params ||= unless connection_type == "Upgrade"
|
||||
route_lookup.params
|
||||
else
|
||||
ws_route_lookup.params
|
||||
end
|
||||
|
||||
@params ||= if @request.param_parser
|
||||
@request.param_parser.not_nil!
|
||||
else
|
||||
|
|
|
@ -8,7 +8,7 @@ module Kemal
|
|||
end
|
||||
|
||||
def call(context)
|
||||
raise Kemal::Exceptions::RouteNotFound.new(context) unless context.ws_route_defined?
|
||||
return call_next(context) unless context.ws_route_defined?
|
||||
super
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue