em-websocket-request 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require 'em-http-request'
2
2
  require "em-ws-request/version"
3
+ require "em-ws-request/options"
3
4
  require "em-ws-request/client"
4
5
  require "em-ws-request/wrapper"
5
6
 
@@ -1,7 +1,7 @@
1
1
  module EventMachine
2
2
  class WebsocketConnection < HttpConnection
3
3
  def setup_request(method, options = {}, c = nil)
4
- c ||= WebsocketClient.new(self, HttpClientOptions.new(@uri, options, method))
4
+ c ||= WebsocketClient.new(self, WsClientOptions.new(@uri, options, method))
5
5
  @deferred ? activate_connection(c) : finalize_request(c)
6
6
  c
7
7
  end
@@ -30,7 +30,7 @@ module EventMachine
30
30
  end
31
31
 
32
32
  class WebsocketClient < HttpClient
33
- PROTOCOL_VERSION = '8'
33
+ PROTOCOL_VERSION = '13'
34
34
 
35
35
  def initialize(conn, options)
36
36
  super(conn, options)
@@ -0,0 +1,5 @@
1
+ module EventMachine
2
+ class WsClientOptions < HttpClientOptions
3
+ def ssl?; @uri.scheme == "wss" || super; end
4
+ end
5
+ end
@@ -300,10 +300,16 @@ class WebSocket
300
300
  @header[$1] = $2
301
301
  @header[$1.downcase()] = $2
302
302
  end
303
+ if !@header["upgrade"]
304
+ raise(WebSocket::Error, "Upgrade header is missing")
305
+ end
303
306
  if !(@header["upgrade"] =~ /\AWebSocket\z/i)
304
307
  raise(WebSocket::Error, "invalid Upgrade: " + @header["upgrade"])
305
308
  end
306
- if !(@header["connection"] =~ /\AUpgrade\z/i)
309
+ if !@header["connection"]
310
+ raise(WebSocket::Error, "Connection header is missing")
311
+ end
312
+ if @header["connection"].split(/,/).grep(/\A\s*Upgrade\s*\z/i).empty?
307
313
  raise(WebSocket::Error, "invalid Connection: " + @header["connection"])
308
314
  end
309
315
  end
@@ -1,3 +1,3 @@
1
1
  module EventMachine
2
- WS_REQUEST_VERSION = "0.0.4"
2
+ WS_REQUEST_VERSION = "0.0.5"
3
3
  end
@@ -6,6 +6,7 @@ module EventMachine
6
6
  @handshaked = true
7
7
  @client = client
8
8
  @web_socket_version = version
9
+ @read_buffer = ''
9
10
  end
10
11
 
11
12
  def send_frame(opcode, data, mask = true)
@@ -18,14 +19,18 @@ module EventMachine
18
19
  end
19
20
 
20
21
  def receive(data)
21
- @incoming_data = data
22
+ @read_buffer << data if data
22
23
  super()
23
24
  end
24
25
 
25
26
  def read(num_bytes)
26
- str = @incoming_data.slice(0, num_bytes)
27
- @incoming_data = @incoming_data[num_bytes..-1]
28
- return str
27
+ if(@read_buffer.size < num_bytes)
28
+ raise EOFError
29
+ else
30
+ str = @read_buffer.slice(0, num_bytes)
31
+ @read_buffer = @read_buffer[num_bytes..-1]
32
+ return str
33
+ end
29
34
  end
30
35
 
31
36
  # Called on a CLOSE frame
@@ -94,11 +94,11 @@ describe EventMachine::WebsocketRequest do
94
94
  http = websocket_test_request
95
95
  http.errback { failed(http) }
96
96
  http.callback { http.send(MSG) }
97
+ http.disconnect { EventMachine.stop }
97
98
  http.stream { |chunk|
99
+ # FIXME We should not receive a chunk!
98
100
  chunk.should be_nil
99
- EventMachine.stop
100
101
  }
101
-
102
102
  }
103
103
  end
104
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-websocket-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-02 00:00:00.000000000 Z
12
+ date: 2012-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-http-request
16
- requirement: &70226843904280 !ruby/object:Gem::Requirement
16
+ requirement: &70159723186380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70226843904280
24
+ version_requirements: *70159723186380
25
25
  description: EventMachine WebSocket client
26
26
  email:
27
27
  - mrykov@gmail.com
@@ -36,6 +36,7 @@ files:
36
36
  - em-websocket-request.gemspec
37
37
  - lib/em-websocket-request.rb
38
38
  - lib/em-ws-request/client.rb
39
+ - lib/em-ws-request/options.rb
39
40
  - lib/em-ws-request/version.rb
40
41
  - lib/em-ws-request/wrapper.rb
41
42
  - spec/websocket_spec.rb