websocket_parser 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/websocket/client_handshake.rb +20 -8
- data/lib/websocket/server_handshake.rb +3 -1
- data/lib/websocket/version.rb +1 -1
- data/lib/websocket_parser.rb +0 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/websocket/handshake_spec.rb +16 -0
- data/websocket_parser.gemspec +0 -2
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc4855a9ac712ce4e9122a142cd5b7c7490fc1f2
|
4
|
+
data.tar.gz: c5f772d978806e57e200e77f833f0af1d86f078d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5152da6ff5e0fbd83670b892744ea26ae641b46710c62be3e405209bc3571fe6d2bfeb38d105336c99a71c5eaa3d6a308ee56d73f3441ef50be9266e11af636d
|
7
|
+
data.tar.gz: 5c20f099efa09f71e44e1e16980c0a924a30dd83e6a9cfe76048966555919a4e8c44263d7116f299458b4e01efbaa3af8a8d1d4c76e3dcefd82969385cc0b7a1
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# WebSocketParser
|
2
2
|
[![Build Status](https://secure.travis-ci.org/afcapel/websocket_parser.png)](http://travis-ci.org/afcapel/websocket_parser)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/afcapel/websocket_parser.png)](https://codeclimate.com/github/afcapel/websocket_parser)
|
3
4
|
|
4
5
|
WebsocketParser is a RFC6455 compliant parser for websocket messages written in Ruby. It
|
5
6
|
is intended to write websockets servers in Ruby, but it only handles the parsing of the
|
@@ -2,12 +2,19 @@ require 'digest/sha1'
|
|
2
2
|
require 'base64'
|
3
3
|
|
4
4
|
module WebSocket
|
5
|
-
class ClientHandshake
|
5
|
+
class ClientHandshake
|
6
|
+
|
7
|
+
attr_reader :verb, :uri, :headers, :proxy, :body, :version
|
6
8
|
|
7
9
|
def self.accept_token_for(websocket_key)
|
8
10
|
Base64.encode64(Digest::SHA1.digest(websocket_key.strip + GUID)).strip
|
9
11
|
end
|
10
12
|
|
13
|
+
def initialize(verb, uri, headers = {}, proxy = {}, body = nil, version = '1.1')
|
14
|
+
@verb, @headers, @proxy, @body, @version = verb, headers, proxy, body, version
|
15
|
+
@uri = uri.is_a?(URI) ? uri : URI(uri.to_s)
|
16
|
+
end
|
17
|
+
|
11
18
|
def errors
|
12
19
|
@errors ||= []
|
13
20
|
end
|
@@ -18,10 +25,8 @@ module WebSocket
|
|
18
25
|
return false
|
19
26
|
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
if headers['Sec-Websocket-Version'].to_i != PROTOCOL_VERSION
|
24
|
-
errors << "Protocol version not supported '#{headers['Sec-Websocket-Version']}'"
|
28
|
+
if websocket_version_header.to_i != PROTOCOL_VERSION
|
29
|
+
errors << "Protocol version not supported '#{websocket_version_header}'"
|
25
30
|
return false
|
26
31
|
end
|
27
32
|
|
@@ -33,16 +38,23 @@ module WebSocket
|
|
33
38
|
end
|
34
39
|
|
35
40
|
def response_headers
|
36
|
-
websocket_key = headers['Sec-Websocket-Key']
|
37
41
|
{
|
38
42
|
'Upgrade' => 'websocket',
|
39
43
|
'Connection' => 'Upgrade',
|
40
|
-
'Sec-WebSocket-Accept' => ClientHandshake.accept_token_for(
|
44
|
+
'Sec-WebSocket-Accept' => ClientHandshake.accept_token_for(websocket_key_header)
|
41
45
|
}
|
42
46
|
end
|
43
47
|
|
48
|
+
def websocket_version_header
|
49
|
+
headers['Sec-WebSocket-Version'] || headers['Sec-Websocket-Version']
|
50
|
+
end
|
51
|
+
|
52
|
+
def websocket_key_header
|
53
|
+
headers['Sec-Websocket-Key'] || headers['Sec-WebSocket-Key']
|
54
|
+
end
|
55
|
+
|
44
56
|
def to_data
|
45
|
-
data = "#{
|
57
|
+
data = "#{verb.to_s.upcase} #{uri.path} HTTP/#{version}#{CRLF}"
|
46
58
|
@headers.each do |field, value|
|
47
59
|
data << "#{field}: #{value}#{CRLF}"
|
48
60
|
end
|
data/lib/websocket/version.rb
CHANGED
data/lib/websocket_parser.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -26,4 +26,20 @@ describe WebSocket::ClientHandshake do
|
|
26
26
|
response.headers['Connection'].should eq('Upgrade')
|
27
27
|
response.headers['Sec-WebSocket-Accept'].should eq('s3pPLMBiTxaQ9kYGzzhZRbK+xOo=')
|
28
28
|
end
|
29
|
+
|
30
|
+
it "can be seariakized to data" do
|
31
|
+
expected_lines = [
|
32
|
+
"GET / HTTP/1.1",
|
33
|
+
"Host: server.example.com",
|
34
|
+
"Upgrade: websocket",
|
35
|
+
"Connection: Upgrade",
|
36
|
+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==",
|
37
|
+
"Origin: http://example.com",
|
38
|
+
"Sec-WebSocket-Protocol: chat, superchat",
|
39
|
+
"Sec-WebSocket-Version: 13",
|
40
|
+
"\r\n"
|
41
|
+
]
|
42
|
+
|
43
|
+
client_handshake.to_data.should eq expected_lines.join("\r\n")
|
44
|
+
end
|
29
45
|
end
|
data/websocket_parser.gemspec
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: websocket_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alberto Fernandez-Capel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: http
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|