Rename to Kemal::WebSocketHandler

This commit is contained in:
Sdogruyol 2015-12-22 20:51:27 +02:00
parent d50d305e99
commit fbc21b197a
3 changed files with 28 additions and 7 deletions

View file

@ -1,8 +1,8 @@
require "./spec_helper"
describe "Kemal::WebsocketHandler" do
describe "Kemal::WebSocketHandler" do
it "doesn't match on wrong route" do
handler = Kemal::WebsocketHandler.new "/" { }
handler = Kemal::WebSocketHandler.new "/" { }
headers = HTTP::Headers{
"Upgrade": "websocket",
"Connection": "Upgrade",
@ -14,7 +14,7 @@ describe "Kemal::WebsocketHandler" do
end
it "matches on given route" do
handler = Kemal::WebsocketHandler.new "/" { }
handler = Kemal::WebSocketHandler.new "/" { }
headers = HTTP::Headers{
"Upgrade": "websocket",
"Connection": "Upgrade",
@ -35,7 +35,7 @@ describe "Kemal::WebsocketHandler" do
"hello #{env.params["message"]}"
end
ws_handler = Kemal::WebsocketHandler.new "/" { }
ws_handler = Kemal::WebSocketHandler.new "/" { }
headers = HTTP::Headers{
"Upgrade": "websocket",
"Connection": "Upgrade",
@ -56,4 +56,25 @@ describe "Kemal::WebsocketHandler" do
response.headers["Sec-WebSocket-Accept"].should eq("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=")
response.upgrade_handler.should_not be_nil
end
it "has a sockets array" do
ws_handler = Kemal::WebSocketHandler.new "/" do |socket|
end
headers = HTTP::Headers{
"Upgrade": "websocket",
"Connection": "Upgrade",
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
}
# Websocket request
request = HTTP::Request.new("GET", "/", headers)
response = ws_handler.call request
response.status_code.should eq(101)
response.headers["Upgrade"].should eq("websocket")
response.headers["Connection"].should eq("Upgrade")
response.headers["Sec-WebSocket-Accept"].should eq("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=")
response.upgrade_handler.should_not be_nil
end
end

View file

@ -7,5 +7,5 @@ HTTP_METHODS = %w(get post put patch delete)
{% end %}
def ws(path, &block : HTTP::WebSocketHandler::WebSocketSession -> _)
Kemal::WebsocketHandler.new path, &block
Kemal::WebSocketHandler.new path, &block
end

View file

@ -1,7 +1,7 @@
# Kemal::WebsocketHandler is used for each define WebSocket route.
# Kemal::WebSocketHandler is used for each define WebSocket route.
# For each WebSocket route a new handler is created and registered to global handlers.
class Kemal::WebsocketHandler < HTTP::WebSocketHandler
class Kemal::WebSocketHandler < HTTP::WebSocketHandler
def initialize(@path, &@proc : WebSocketSession ->)
Kemal.config.add_ws_handler self
end