websocket-driver 0.7.4 → 0.7.6

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: 91c58586ddd290ad5d320267e36706bdbcffb09c7ba5300d6c3fcd50f342ec2f
4
- data.tar.gz: 7f5afd33de5b0c0e68d7d4cbab726e7ada8200f1b5916e01feb6a3508e3f3e51
3
+ metadata.gz: 48624348056a8a90b22cf6844120166be3ec700a80ec4ab23c1d6c1f5e43aa1a
4
+ data.tar.gz: 0f157eaba15f2cd8c544042700159a692b0bf74f71a03c40b3da04a705409236
5
5
  SHA512:
6
- metadata.gz: 92ececf04fb09b31c8fd1617a38351d7a04c4306f3a27b7061e1220710a5a703da162ca0b47ee2fbdf63e20606040a022de61c51c651add2356665526adffe46
7
- data.tar.gz: f89d71520719be104eb649c318ca85bdd107ec875a62405061fe0268d9df08b0487fe333c531d4635950245ef2879c9fc43c8a148a63afc97f508f28cc4c7397
6
+ metadata.gz: f27c8eafe669ee83b263f56d1b0aeb49bcfba6c5bcc1b027b3bf3a04f71c58e7d9bc6fa99a24f8f4724f6f3d5961a7c90c2fdea978b6f9f1324d5a3f1012d056
7
+ data.tar.gz: 833502731fc73a3b05664d29343199e4c07e5b77825b5a3b2b851d6742506d7c33207a5da0369f692cc073c0e192583db083ba127abaa85eb9b130b4ac1aeb7f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 0.7.6 / 2023-07-25
2
+
3
+ - Fix handling of default ports in `Host` headers on Ruby 3.1+
4
+
5
+ ### 0.7.5 / 2021-06-12
6
+
7
+ - Do not change the encoding of strings passed to `Driver#text`
8
+
1
9
  ### 0.7.4 / 2021-05-24
2
10
 
3
11
  - Optimise conversions between strings and byte arrays and related encoding
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2010-2021 James Coglan
1
+ Copyright 2010-2023 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
@@ -23,11 +23,10 @@ module WebSocket
23
23
  raise URIError, "#{ socket.url } is not a valid WebSocket URL"
24
24
  end
25
25
 
26
- host = uri.host + (uri.port ? ":#{ uri.port }" : '')
27
26
  path = (uri.path == '') ? '/' : uri.path
28
27
  @pathname = path + (uri.query ? '?' + uri.query : '')
29
28
 
30
- @headers['Host'] = host
29
+ @headers['Host'] = Driver.host_header(uri)
31
30
  @headers['Upgrade'] = 'websocket'
32
31
  @headers['Connection'] = 'Upgrade'
33
32
  @headers['Sec-WebSocket-Key'] = @key
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  module WebSocket
2
4
  class Driver
3
5
 
@@ -164,7 +166,7 @@ module WebSocket
164
166
  message.rsv1 = message.rsv2 = message.rsv3 = false
165
167
  message.opcode = OPCODES[type || (String === buffer ? :text : :binary)]
166
168
 
167
- payload = Driver.encode(buffer, Encoding::BINARY)
169
+ payload = Driver.encode(buffer)
168
170
  payload = [code, payload].pack('S>a*') if code
169
171
  message.data = payload
170
172
 
@@ -4,8 +4,6 @@ module WebSocket
4
4
  class Proxy
5
5
  include EventEmitter
6
6
 
7
- PORTS = { 'ws' => 80, 'wss' => 443 }
8
-
9
7
  attr_reader :status, :headers
10
8
 
11
9
  def initialize(client, origin, options)
@@ -20,7 +18,7 @@ module WebSocket
20
18
  @state = 0
21
19
 
22
20
  @headers = Headers.new
23
- @headers['Host'] = @origin.host + (@origin.port ? ":#{ @origin.port }" : '')
21
+ @headers['Host'] = Driver.host_header(@origin)
24
22
  @headers['Connection'] = 'keep-alive'
25
23
  @headers['Proxy-Connection'] = 'keep-alive'
26
24
 
@@ -42,6 +42,7 @@ module WebSocket
42
42
  end
43
43
 
44
44
  MAX_LENGTH = 0x3ffffff
45
+ PORTS = { 'ws' => 80, 'wss' => 443 }
45
46
  STATES = [:connecting, :open, :closing, :closed]
46
47
 
47
48
  ConnectEvent = Struct.new(nil)
@@ -115,7 +116,7 @@ module WebSocket
115
116
  end
116
117
 
117
118
  def text(message)
118
- message = message.encode(Encoding::UTF_8) unless message.encoding == Encoding::UTF_8
119
+ message = Driver.encode(message, Encoding::UTF_8)
119
120
  frame(message, :text)
120
121
  end
121
122
 
@@ -194,19 +195,27 @@ module WebSocket
194
195
  end
195
196
  end
196
197
 
197
- def self.encode(string, encoding = nil)
198
- case string
199
- when Array then
200
- string = string.pack('C*')
201
- encoding ||= Encoding::BINARY
202
- when String then
203
- encoding ||= Encoding::UTF_8
198
+ def self.encode(data, encoding = nil)
199
+ if Array === data
200
+ encoding ||= Encoding::BINARY
201
+ return data.pack('C*').force_encoding(encoding)
204
202
  end
205
- unless string.encoding == encoding
206
- string = string.dup if string.frozen?
207
- string.force_encoding(encoding)
203
+
204
+ encoding ||= Encoding::UTF_8
205
+
206
+ return data if data.encoding == encoding
207
+ return data.encode(encoding) unless data.encoding == Encoding::BINARY
208
+
209
+ data = data.dup if data.frozen?
210
+ data.force_encoding(encoding)
211
+ end
212
+
213
+ def self.host_header(uri)
214
+ host = uri.host
215
+ if uri.port and uri.port != PORTS[uri.scheme]
216
+ host += ":#{uri.port}"
208
217
  end
209
- string
218
+ host
210
219
  end
211
220
 
212
221
  def self.validate_options(options, valid_keys)
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.4
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Coglan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-24 00:00:00.000000000 Z
11
+ date: 2023-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-extensions
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.1.6
138
+ rubygems_version: 3.4.10
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: WebSocket protocol handler with pluggable I/O