websocket-driver 0.7.1 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b7a3b9878d6efb8ad25a608fd06548f4be94454406894588e15f856f4451746
4
- data.tar.gz: a5f98cbda60d85887857b75a967ad8d33a41e549781739374865e05a76304e7b
3
+ metadata.gz: 11392831462e0bee833bdb3ac3f6f09de232e2e8cc7a19799ce0ebb8e7238ea1
4
+ data.tar.gz: 3b4555cc645e77d0166ff9657dc23c306bf48296e94a1520de703f9ab72120f1
5
5
  SHA512:
6
- metadata.gz: fca692d01fb40ad07be65a0050923e03084841e995d53b3580bd84265b74c1a3411b8c4f16f0e319a2a9acb7811e48ad13bc43bc81023d308fb7ea385e150d0d
7
- data.tar.gz: 48e438dea20c9dd8a90224ec32d3d16da1b04f145070e15d9bac741ad39717f04a246631df0475c266f28e495001f41d14f2534c118243075f8abc0921868524
6
+ metadata.gz: 378aaf1b46a663dccd4dbc8ec25e515e9acb7b2c760b7b62c199185e11466d9c2fd6482b17fb51157a03030e0c9065c7f6a6201c61a7f45fc940365cce036626
7
+ data.tar.gz: 783523c78a09ced14fe3e4be497b7fb5e6f22755d6b2dafa5b9b02ed72427512d7b70185dbff43e1df3a924fa086a28334403d7c02b5bc2762fbb33dcf339e3a
@@ -1,3 +1,13 @@
1
+ ### 0.7.3 / 2020-07-09
2
+
3
+ - Let the client accept HTTP responses that have an empty reason phrase
4
+ following the `101` status code
5
+
6
+ ### 0.7.2 / 2020-05-22
7
+
8
+ - Emit `ping` and `pong` events from the `Server` driver
9
+ - Handle draft-76 handshakes correctly if the request's body is a frozen string
10
+
1
11
  ### 0.7.1 / 2019-06-10
2
12
 
3
13
  - Catch any exceptions produced while generating a handshake response and send a
@@ -5,6 +15,7 @@
5
15
  - Pick the RFC-6455 protocol version if the request contains any of the headers
6
16
  used by that version
7
17
  - Handle errors encountered while handling malformed draft-76 requests
18
+ - Change license from MIT to Apache 2.0
8
19
 
9
20
  ### 0.7.0 / 2017-09-11
10
21
 
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2010-2019 James Coglan
1
+ Copyright 2010-2020 James Coglan
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4
4
  this file except in compliance with the License. You may obtain a copy of the
data/README.md CHANGED
@@ -274,33 +274,33 @@ Note that most of these methods are commands: if they produce data that should
274
274
  be sent over the socket, they will give this to you by calling
275
275
  `socket.write(string)`.
276
276
 
277
- #### `driver.on :open, -> (event) { }`
277
+ #### `driver.on :open, -> (event) {}`
278
278
 
279
279
  Adds a callback block to execute when the socket becomes open.
280
280
 
281
- #### `driver.on :message, -> (event) { }`
281
+ #### `driver.on :message, -> (event) {}`
282
282
 
283
283
  Adds a callback block to execute when a message is received. `event` will have a
284
284
  `data` attribute containing either a string in the case of a text message or an
285
285
  array of integers in the case of a binary message.
286
286
 
287
- #### `driver.on :error, -> (event) { }`
287
+ #### `driver.on :error, -> (event) {}`
288
288
 
289
289
  Adds a callback to execute when a protocol error occurs due to the other peer
290
290
  sending an invalid byte sequence. `event` will have a `message` attribute
291
291
  describing the error.
292
292
 
293
- #### `driver.on :close, -> (event) { }`
293
+ #### `driver.on :close, -> (event) {}`
294
294
 
295
295
  Adds a callback block to execute when the socket becomes closed. The `event`
296
296
  object has `code` and `reason` attributes.
297
297
 
298
- #### `driver.on :ping, -> (event) { }`
298
+ #### `driver.on :ping, -> (event) {}`
299
299
 
300
300
  Adds a callback block to execute when a ping is received. You do not need to
301
301
  handle this by sending a pong frame yourself; the driver handles this for you.
302
302
 
303
- #### `driver.on :pong, -> (event) { }`
303
+ #### `driver.on :pong, -> (event) {}`
304
304
 
305
305
  Adds a callback block to execute when a pong is received. If this was in
306
306
  response to a ping you sent, you can also handle this event via the
@@ -215,7 +215,7 @@ module WebSocket
215
215
  def self.validate_options(options, valid_keys)
216
216
  options.keys.each do |key|
217
217
  unless valid_keys.include?(key)
218
- raise ConfigurationError, "Unrecognized option: #{key.inspect}"
218
+ raise ConfigurationError, "Unrecognized option: #{ key.inspect }"
219
219
  end
220
220
  end
221
221
  end
@@ -20,10 +20,10 @@ module WebSocket
20
20
 
21
21
  uri = URI.parse(@socket.url)
22
22
  unless VALID_SCHEMES.include?(uri.scheme)
23
- raise URIError, "#{socket.url} is not a valid WebSocket URL"
23
+ raise URIError, "#{ socket.url } is not a valid WebSocket URL"
24
24
  end
25
25
 
26
- host = uri.host + (uri.port ? ":#{uri.port}" : '')
26
+ host = uri.host + (uri.port ? ":#{ uri.port }" : '')
27
27
  path = (uri.path == '') ? '/' : uri.path
28
28
  @pathname = path + (uri.query ? '?' + uri.query : '')
29
29
 
@@ -44,7 +44,7 @@ module WebSocket
44
44
  end
45
45
 
46
46
  def version
47
- "hybi-#{VERSION}"
47
+ "hybi-#{ VERSION }"
48
48
  end
49
49
 
50
50
  def proxy(origin, options = {})
@@ -73,19 +73,19 @@ module WebSocket
73
73
  parse(@http.body)
74
74
  end
75
75
 
76
- private
76
+ private
77
77
 
78
78
  def handshake_request
79
79
  extensions = @extensions.generate_offer
80
80
  @headers['Sec-WebSocket-Extensions'] = extensions if extensions
81
81
 
82
- start = "GET #{@pathname} HTTP/1.1"
82
+ start = "GET #{ @pathname } HTTP/1.1"
83
83
  headers = [start, @headers.to_s, '']
84
84
  headers.join("\r\n")
85
85
  end
86
86
 
87
87
  def fail_handshake(message)
88
- message = "Error during WebSocket handshake: #{message}"
88
+ message = "Error during WebSocket handshake: #{ message }"
89
89
  @ready_state = 3
90
90
  emit(:error, ProtocolError.new(message))
91
91
  emit(:close, CloseEvent.new(ERRORS[:protocol_error], message))
@@ -96,7 +96,7 @@ module WebSocket
96
96
  @headers = Headers.new(@http.headers)
97
97
 
98
98
  unless @http.code == 101
99
- return fail_handshake("Unexpected response code: #{@http.code}")
99
+ return fail_handshake("Unexpected response code: #{ @http.code }")
100
100
  end
101
101
 
102
102
  upgrade = @http['Upgrade'] || ''
@@ -6,9 +6,10 @@ module WebSocket
6
6
 
7
7
  def initialize(socket, options = {})
8
8
  super
9
- input = @socket.env['rack.input']
9
+ input = (@socket.env['rack.input'] || StringIO.new('')).read
10
+ input = input.dup if input.frozen?
10
11
  @stage = -1
11
- @body = (input ? input.read : String.new('')).force_encoding(BINARY)
12
+ @body = input.force_encoding(BINARY)
12
13
 
13
14
  @headers.clear
14
15
  @headers['Upgrade'] = 'WebSocket'
@@ -25,7 +25,7 @@ module WebSocket
25
25
  return if value.nil?
26
26
  key = HTTP.normalize_header(name)
27
27
  return unless @sent.add?(key) or ALLOWED_DUPLICATES.include?(key)
28
- @lines << "#{name.strip}: #{value.to_s.strip}\r\n"
28
+ @lines << "#{ name.strip }: #{ value.to_s.strip }\r\n"
29
29
  end
30
30
 
31
31
  def inspect
@@ -52,7 +52,7 @@ module WebSocket
52
52
  MIN_RESERVED_ERROR = 3000
53
53
  MAX_RESERVED_ERROR = 4999
54
54
 
55
- PACK_FORMATS = {2 => 'n', 8 => 'Q>'}
55
+ PACK_FORMATS = { 2 => 'n', 8 => 'Q>' }
56
56
 
57
57
  def initialize(socket, options = {})
58
58
  super
@@ -78,7 +78,7 @@ module WebSocket
78
78
  end
79
79
 
80
80
  def version
81
- "hybi-#{VERSION}"
81
+ "hybi-#{ VERSION }"
82
82
  end
83
83
 
84
84
  def add_extension(extension)
@@ -228,7 +228,7 @@ module WebSocket
228
228
  version = @socket.env['HTTP_SEC_WEBSOCKET_VERSION']
229
229
 
230
230
  unless version == VERSION
231
- raise ProtocolError.new("Unsupported WebSocket version: #{VERSION}")
231
+ raise ProtocolError.new("Unsupported WebSocket version: #{ VERSION }")
232
232
  end
233
233
 
234
234
  unless sec_key
@@ -281,17 +281,17 @@ module WebSocket
281
281
 
282
282
  unless @extensions.valid_frame_rsv?(@frame)
283
283
  return fail(:protocol_error,
284
- "One or more reserved bits are on: reserved1 = #{@frame.rsv1 ? 1 : 0}" +
285
- ", reserved2 = #{@frame.rsv2 ? 1 : 0 }" +
286
- ", reserved3 = #{@frame.rsv3 ? 1 : 0 }")
284
+ "One or more reserved bits are on: reserved1 = #{ @frame.rsv1 ? 1 : 0 }" +
285
+ ", reserved2 = #{ @frame.rsv2 ? 1 : 0 }" +
286
+ ", reserved3 = #{ @frame.rsv3 ? 1 : 0 }")
287
287
  end
288
288
 
289
289
  unless OPCODES.values.include?(@frame.opcode)
290
- return fail(:protocol_error, "Unrecognized frame opcode: #{@frame.opcode}")
290
+ return fail(:protocol_error, "Unrecognized frame opcode: #{ @frame.opcode }")
291
291
  end
292
292
 
293
293
  unless MESSAGE_OPCODES.include?(@frame.opcode) or @frame.final
294
- return fail(:protocol_error, "Received fragmented control frame: opcode = #{@frame.opcode}")
294
+ return fail(:protocol_error, "Received fragmented control frame: opcode = #{ @frame.opcode }")
295
295
  end
296
296
 
297
297
  if @message and OPENING_OPCODES.include?(@frame.opcode)
@@ -321,7 +321,7 @@ module WebSocket
321
321
  @stage = @frame.masked ? 3 : 4
322
322
 
323
323
  unless MESSAGE_OPCODES.include?(@frame.opcode) or @frame.length <= 125
324
- return fail(:protocol_error, "Received control frame having too long payload: #{@frame.length}")
324
+ return fail(:protocol_error, "Received control frame having too long payload: #{ @frame.length }")
325
325
  end
326
326
 
327
327
  return unless check_frame_length
@@ -4,7 +4,7 @@ module WebSocket
4
4
  class Proxy
5
5
  include EventEmitter
6
6
 
7
- PORTS = {'ws' => 80, 'wss' => 443}
7
+ PORTS = { 'ws' => 80, 'wss' => 443 }
8
8
 
9
9
  attr_reader :status, :headers
10
10
 
@@ -20,7 +20,7 @@ module WebSocket
20
20
  @state = 0
21
21
 
22
22
  @headers = Headers.new
23
- @headers['Host'] = @origin.host + (@origin.port ? ":#{@origin.port}" : '')
23
+ @headers['Host'] = @origin.host + (@origin.port ? ":#{ @origin.port }" : '')
24
24
  @headers['Connection'] = 'keep-alive'
25
25
  @headers['Proxy-Connection'] = 'keep-alive'
26
26
 
@@ -41,7 +41,7 @@ module WebSocket
41
41
  @state = 1
42
42
 
43
43
  port = @origin.port || PORTS[@origin.scheme]
44
- start = "CONNECT #{@origin.host}:#{port} HTTP/1.1"
44
+ start = "CONNECT #{ @origin.host }:#{ port } HTTP/1.1"
45
45
  headers = [start, @headers.to_s, '']
46
46
 
47
47
  @socket.write(headers.join("\r\n"))
@@ -58,7 +58,7 @@ module WebSocket
58
58
  if @status == 200
59
59
  emit(:connect, ConnectEvent.new)
60
60
  else
61
- message = "Can't establish a connection to the server at #{@socket.url}"
61
+ message = "Can't establish a connection to the server at #{ @socket.url }"
62
62
  emit(:error, ProtocolError.new(message))
63
63
  end
64
64
  end
@@ -2,7 +2,7 @@ module WebSocket
2
2
  class Driver
3
3
 
4
4
  class Server < Driver
5
- EVENTS = %w[open message error close]
5
+ EVENTS = %w[open message error close ping pong]
6
6
 
7
7
  def initialize(socket, options = {})
8
8
  super
@@ -17,9 +17,9 @@ module WebSocket
17
17
  def url
18
18
  return nil unless e = env
19
19
 
20
- url = "ws://#{e['HTTP_HOST']}"
20
+ url = "ws://#{ e['HTTP_HOST'] }"
21
21
  url << e['PATH_INFO']
22
- url << "?#{e['QUERY_STRING']}" unless e['QUERY_STRING'] == ''
22
+ url << "?#{ e['QUERY_STRING'] }" unless e['QUERY_STRING'] == ''
23
23
  url
24
24
  end
25
25
 
@@ -30,11 +30,11 @@ module WebSocket
30
30
  super
31
31
  @headers.each do |name, value|
32
32
  rack_name = name.upcase.gsub(/-/, '_')
33
- rack_name = "HTTP_#{rack_name}" unless RESERVED_HEADERS.include?(name)
33
+ rack_name = "HTTP_#{ rack_name }" unless RESERVED_HEADERS.include?(name)
34
34
  @env[rack_name] = value
35
35
  end
36
36
  if host = @env['HTTP_HOST']
37
- uri = URI.parse("http://#{host}")
37
+ uri = URI.parse("http://#{ host }")
38
38
  @env['SERVER_NAME'] = uri.host
39
39
  @env['SERVER_PORT'] = uri.port.to_s
40
40
  end
@@ -4,7 +4,7 @@ module WebSocket
4
4
  class Response
5
5
  include Headers
6
6
 
7
- STATUS_LINE = /^(HTTP\/[0-9]+\.[0-9]+) ([0-9]{3}) ([\x20-\x7e]+)$/
7
+ STATUS_LINE = /^(HTTP\/[0-9]+\.[0-9]+) ([0-9]{3}) ([\x20-\x7e]*)$/
8
8
 
9
9
  attr_reader :code
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websocket-driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Coglan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-10 00:00:00.000000000 Z
11
+ date: 2020-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-extensions
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description:
83
+ description:
84
84
  email: jcoglan@gmail.com
85
85
  executables: []
86
86
  extensions:
@@ -116,7 +116,7 @@ homepage: https://github.com/faye/websocket-driver-ruby
116
116
  licenses:
117
117
  - Apache-2.0
118
118
  metadata: {}
119
- post_install_message:
119
+ post_install_message:
120
120
  rdoc_options:
121
121
  - "--main"
122
122
  - README.md
@@ -135,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.0.3
139
- signing_key:
138
+ rubygems_version: 3.1.2
139
+ signing_key:
140
140
  specification_version: 4
141
141
  summary: WebSocket protocol handler with pluggable I/O
142
142
  test_files: []