forked from igrigorik/em-websocket
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request igrigorik#63 from miksago/draft-13
Support Draft 13 (minimal - lacking some close code nice to haves)
- Loading branch information
Showing
5 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module EventMachine | ||
module WebSocket | ||
class Handler13 < Handler | ||
include Handshake04 | ||
include Framing07 | ||
include MessageProcessor06 | ||
include Close06 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'helper' | ||
require 'integration/shared_examples' | ||
|
||
describe "draft13" do | ||
include EM::SpecHelper | ||
default_timeout 1 | ||
|
||
before :each do | ||
@request = { | ||
:port => 80, | ||
:method => "GET", | ||
:path => "/demo", | ||
:headers => { | ||
'Host' => 'example.com', | ||
'Upgrade' => 'websocket', | ||
'Connection' => 'Upgrade', | ||
'Sec-WebSocket-Key' => 'dGhlIHNhbXBsZSBub25jZQ==', | ||
'Sec-WebSocket-Protocol' => 'sample', | ||
'Sec-WebSocket-Origin' => 'http://example.com', | ||
'Sec-WebSocket-Version' => '13' | ||
} | ||
} | ||
|
||
@response = { | ||
:protocol => "HTTP/1.1 101 Switching Protocols\r\n", | ||
:headers => { | ||
"Upgrade" => "websocket", | ||
"Connection" => "Upgrade", | ||
"Sec-WebSocket-Accept" => "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", | ||
} | ||
} | ||
end | ||
|
||
it_behaves_like "a websocket server" do | ||
def start_server | ||
EM::WebSocket.start(:host => "0.0.0.0", :port => 12345) { |ws| | ||
yield ws | ||
} | ||
end | ||
|
||
def start_client | ||
client = EM.connect('0.0.0.0', 12345, Draft07FakeWebSocketClient) | ||
client.send_data(format_request(@request)) | ||
yield client if block_given? | ||
end | ||
end | ||
|
||
it "should send back the correct handshake response" do | ||
em { | ||
EM.add_timer(0.1) do | ||
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 12345) { } | ||
|
||
# Create a fake client which sends draft 07 handshake | ||
connection = EM.connect('0.0.0.0', 12345, Draft07FakeWebSocketClient) | ||
connection.send_data(format_request(@request)) | ||
|
||
connection.onopen { | ||
connection.handshake_response.lines.sort. | ||
should == format_response(@response).lines.sort | ||
done | ||
} | ||
end | ||
} | ||
end | ||
end |