websocket-driver 0.6.3-java → 0.6.4-java

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
  SHA1:
3
- metadata.gz: 7a9a3b19bd45673c1f7802c01d1108331f2c49bf
4
- data.tar.gz: 5db37f196e48222a6544aa8313b86c276a8d7df6
3
+ metadata.gz: 0ca9e841dbce35de07a9afcd29d6f0660d01a68c
4
+ data.tar.gz: c1729d6498efc70411f686ce2389985df7d0be55
5
5
  SHA512:
6
- metadata.gz: af8a11bc2a93a6863d888ae590c2114fa85851bc3fe1cd2a7449cafdb1a8c4207bf45f3879df92d08c84a2b6fc8e11705ae59bf7b4c93d717755577a1c51b052
7
- data.tar.gz: 42bbe9765306e54553d9dc717def5f0308e04910b49fcaafa696c82a599d0b4a2edbb2bdf16cd3667f8c53935aa4f927f76a4d0fe926052b6b3f96eb83edd025
6
+ metadata.gz: b9e54bfd44ef74195ef0951816a6db18b4ec0fdadd7327d5d42e65ec02ab8847cb72a1b25cc136d61c324c741c46c7295abb24c637bd231a9420b50bb7ccfd5f
7
+ data.tar.gz: 459bb5004b7960ba06da380d716279a784c89a1ab28dead9b252e0b1bdfb38825ad17a1ae6d4afc446dd200cb316655e12ea67f0d4bdf4735c68395547e2528a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.6.4 / 2016-05-20
2
+
3
+ * Amend warnings issued when running with -W2
4
+ * Make sure message strings passed in by the app are transcoded to UTF-8
5
+ * Copy strings if necessary for frozen-string compatibility
6
+
1
7
  ### 0.6.3 / 2015-11-06
2
8
 
3
9
  * Reject draft-76 handshakes if their Sec-WebSocket-Key headers are invalid
data/README.md CHANGED
@@ -373,7 +373,7 @@ using the `Sec-WebSocket-Protocol` mechanism. This value becomes available after
373
373
 
374
374
  (The MIT License)
375
375
 
376
- Copyright (c) 2010-2015 James Coglan
376
+ Copyright (c) 2010-2016 James Coglan
377
377
 
378
378
  Permission is hereby granted, free of charge, to any person obtaining a copy of
379
379
  this software and associated documentation files (the 'Software'), to deal in
@@ -33,13 +33,12 @@ module WebSocket
33
33
  end
34
34
  end
35
35
 
36
- unless String.instance_methods.include?(:force_encoding)
37
- require root + '/utf8_match'
38
- end
39
-
40
36
  MAX_LENGTH = 0x3ffffff
41
37
  STATES = [:connecting, :open, :closing, :closed]
42
38
 
39
+ BINARY = 'ASCII-8BIT'
40
+ UNICODE = 'UTF-8'
41
+
43
42
  ConnectEvent = Struct.new(nil)
44
43
  OpenEvent = Struct.new(nil)
45
44
  MessageEvent = Struct.new(:data)
@@ -94,13 +93,14 @@ module WebSocket
94
93
  return false unless @ready_state == 0
95
94
  response = handshake_response
96
95
  return false unless response
97
- @socket.write(Driver.encode(response, :binary))
96
+ @socket.write(response)
98
97
  open unless @stage == -1
99
98
  true
100
99
  end
101
100
 
102
101
  def text(message)
103
- frame(message)
102
+ message = message.encode(UNICODE) unless message.encoding.name == UNICODE
103
+ frame(message, :text)
104
104
  end
105
105
 
106
106
  def binary(message)
@@ -159,14 +159,15 @@ module WebSocket
159
159
  case string
160
160
  when Array then
161
161
  string = string.pack('C*')
162
- encoding ||= :binary
162
+ encoding ||= BINARY
163
163
  when String then
164
- encoding ||= :utf8
164
+ encoding ||= UNICODE
165
+ end
166
+ unless string.encoding.name == encoding
167
+ string = string.dup if string.frozen?
168
+ string.force_encoding(encoding)
165
169
  end
166
- encodings = {:utf8 => 'UTF-8', :binary => 'ASCII-8BIT'}
167
- string.force_encoding(encodings[encoding]) if string.respond_to?(:force_encoding)
168
- return nil if encoding == :utf8 and not valid_utf8?(string)
169
- string
170
+ string.valid_encoding? ? string : nil
170
171
  end
171
172
 
172
173
  def self.validate_options(options, valid_keys)
@@ -177,14 +178,6 @@ module WebSocket
177
178
  end
178
179
  end
179
180
 
180
- def self.valid_utf8?(string)
181
- if defined?(UTF8_MATCH)
182
- UTF8_MATCH =~ string ? true : false
183
- else
184
- string.valid_encoding?
185
- end
186
- end
187
-
188
181
  def self.websocket?(env)
189
182
  connection = env['HTTP_CONNECTION'] || ''
190
183
  upgrade = env['HTTP_UPGRADE'] || ''
@@ -53,7 +53,7 @@ module WebSocket
53
53
 
54
54
  def start
55
55
  return false unless @ready_state == -1
56
- @socket.write(Driver.encode(handshake_request, :binary))
56
+ @socket.write(handshake_request)
57
57
  @ready_state = 0
58
58
  true
59
59
  end
@@ -4,7 +4,9 @@ module WebSocket
4
4
  class Draft75 < Driver
5
5
  def initialize(socket, options = {})
6
6
  super
7
- @stage = 0
7
+
8
+ @stage = 0
9
+ @closing = false
8
10
 
9
11
  @headers['Upgrade'] = 'WebSocket'
10
12
  @headers['Connection'] = 'Upgrade'
@@ -54,7 +56,7 @@ module WebSocket
54
56
  when 2 then
55
57
  if octet == 0xFF
56
58
  @stage = 0
57
- emit(:message, MessageEvent.new(Driver.encode(@buffer, :utf8)))
59
+ emit(:message, MessageEvent.new(Driver.encode(@buffer, UNICODE)))
58
60
  else
59
61
  if @length
60
62
  @skipped += 1
@@ -8,7 +8,7 @@ module WebSocket
8
8
  super
9
9
  input = @socket.env['rack.input']
10
10
  @stage = -1
11
- @body = Driver.encode(input ? input.read : '', :binary)
11
+ @body = (input ? input.read : String.new('')).force_encoding(BINARY)
12
12
 
13
13
  @headers.clear
14
14
  @headers['Upgrade'] = 'WebSocket'
@@ -70,7 +70,7 @@ module WebSocket
70
70
 
71
71
  def send_handshake_body
72
72
  return unless signature = handshake_signature
73
- @socket.write(Driver.encode(signature, :binary))
73
+ @socket.write(signature)
74
74
  @stage = 0
75
75
  open
76
76
  parse(@body[BODY_SIZE..-1]) if @body.bytesize > BODY_SIZE
@@ -64,6 +64,8 @@ module WebSocket
64
64
  @require_masking = options[:require_masking]
65
65
  @ping_callbacks = {}
66
66
 
67
+ @frame = @message = nil
68
+
67
69
  return unless @socket.respond_to?(:env)
68
70
 
69
71
  sec_key = @socket.env['HTTP_SEC_WEBSOCKET_KEY']
@@ -127,10 +129,6 @@ module WebSocket
127
129
  end
128
130
  end
129
131
 
130
- def text(message)
131
- frame(message, :text)
132
- end
133
-
134
132
  def binary(message)
135
133
  frame(message, :binary)
136
134
  end
@@ -201,8 +199,6 @@ module WebSocket
201
199
 
202
200
  def send_frame(frame)
203
201
  length = frame.length
204
- header = (length <= 125) ? 2 : (length <= 65535 ? 4 : 10)
205
- offset = header + (frame.masked ? 4 : 0)
206
202
  buffer = []
207
203
  masked = frame.masked ? MASK : 0
208
204
 
@@ -356,7 +352,7 @@ module WebSocket
356
352
 
357
353
  when OPCODES[:close] then
358
354
  code = (bytesize >= 2) ? payload.unpack(PACK_FORMATS[2]).first : nil
359
- reason = (bytesize > 2) ? Driver.encode(bytes[2..-1] || [], :utf8) : nil
355
+ reason = (bytesize > 2) ? Driver.encode(bytes[2..-1] || [], UNICODE) : nil
360
356
 
361
357
  unless (bytesize == 0) or
362
358
  (code && code >= MIN_RESERVED_ERROR && code <= MAX_RESERVED_ERROR) or
@@ -374,7 +370,7 @@ module WebSocket
374
370
  frame(payload, :pong)
375
371
 
376
372
  when OPCODES[:pong] then
377
- message = Driver.encode(payload, :utf8)
373
+ message = Driver.encode(payload, UNICODE)
378
374
  callback = @ping_callbacks[message]
379
375
  @ping_callbacks.delete(message)
380
376
  callback.call if callback
@@ -391,7 +387,7 @@ module WebSocket
391
387
 
392
388
  case message.opcode
393
389
  when OPCODES[:text] then
394
- payload = Driver.encode(payload, :utf8)
390
+ payload = Driver.encode(payload, UNICODE)
395
391
  when OPCODES[:binary]
396
392
  payload = payload.bytes.to_a
397
393
  end
@@ -14,7 +14,7 @@ module WebSocket
14
14
  @rsv2 = false
15
15
  @rsv3 = false
16
16
  @opcode = nil
17
- @data = Driver.encode('', :binary)
17
+ @data = String.new('').force_encoding(BINARY)
18
18
  end
19
19
 
20
20
  def <<(frame)
@@ -44,7 +44,7 @@ module WebSocket
44
44
  start = "CONNECT #{@origin.host}:#{port} HTTP/1.1"
45
45
  headers = [start, @headers.to_s, '']
46
46
 
47
- @socket.write(Driver.encode(headers.join("\r\n"), :binary))
47
+ @socket.write(headers.join("\r\n"))
48
48
  true
49
49
  end
50
50
 
@@ -58,7 +58,7 @@ module WebSocket
58
58
  end
59
59
 
60
60
  def write(buffer)
61
- @socket.write(Driver.encode(buffer, :binary))
61
+ @socket.write(buffer)
62
62
  end
63
63
 
64
64
  private
@@ -6,13 +6,13 @@ module WebSocket
6
6
  MINIMUM_AUTOMATIC_PRUNE_OFFSET = 128
7
7
 
8
8
  def initialize
9
- @buffer = Driver.encode('', :binary)
9
+ @buffer = String.new('').force_encoding(BINARY)
10
10
  @offset = 0
11
11
  end
12
12
 
13
13
  def put(chunk)
14
14
  return unless chunk and chunk.bytesize > 0
15
- @buffer << Driver.encode(chunk, :binary)
15
+ @buffer << chunk.force_encoding(BINARY)
16
16
  end
17
17
 
18
18
  # Read bytes from the data:
@@ -42,7 +42,7 @@ module WebSocket
42
42
  buffer_size = @buffer.bytesize
43
43
 
44
44
  if @offset > buffer_size
45
- @buffer = Driver.encode('', :binary)
45
+ @buffer = String.new('').force_encoding(BINARY)
46
46
  else
47
47
  @buffer = @buffer.byteslice(@offset, buffer_size - @offset)
48
48
  end
@@ -39,6 +39,7 @@ module WebSocket
39
39
 
40
40
  def initialize
41
41
  @buffer = []
42
+ @env = {}
42
43
  @headers = {}
43
44
  @stage = 0
44
45
  end
@@ -75,7 +76,7 @@ module WebSocket
75
76
  error if @stage < 2 and @buffer.size > MAX_LINE_LENGTH
76
77
  end
77
78
  end
78
- @env['rack.input'] = StringIO.new(string_buffer) if @env
79
+ @env['rack.input'] = StringIO.new(string_buffer)
79
80
  end
80
81
 
81
82
  private
Binary file
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.6.3
4
+ version: 0.6.4
5
5
  platform: java
6
6
  authors:
7
7
  - James Coglan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-06 00:00:00.000000000 Z
11
+ date: 2016-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-extensions
@@ -105,7 +105,6 @@ files:
105
105
  - lib/websocket/driver/proxy.rb
106
106
  - lib/websocket/driver/server.rb
107
107
  - lib/websocket/driver/stream_reader.rb
108
- - lib/websocket/driver/utf8_match.rb
109
108
  - lib/websocket/http.rb
110
109
  - lib/websocket/http/headers.rb
111
110
  - lib/websocket/http/request.rb
@@ -1,6 +0,0 @@
1
- module WebSocket
2
- class Driver
3
- # http://www.w3.org/International/questions/qa-forms-utf-8.en.php
4
- UTF8_MATCH = /^([\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/
5
- end
6
- end