update to version 0.7.6

This commit is contained in:
wang--ge 2023-11-15 15:09:21 +08:00
parent 613583ef29
commit c5a8a4aa96
6 changed files with 7 additions and 147 deletions

Binary file not shown.

BIN
0.7.6.tar.gz Normal file

Binary file not shown.

View File

@ -1,140 +0,0 @@
From 716f19d79e94541bd525f228bfe184420c7c44ad Mon Sep 17 00:00:00 2001
From: James Coglan <jcoglan@gmail.com>
Date: Sat, 10 Sep 2022 15:37:55 +0100
Subject: [PATCH] Fix handling of default ports on Ruby 3.1
---
lib/websocket/driver.rb | 9 ++++++
lib/websocket/driver/client.rb | 3 +-
lib/websocket/driver/proxy.rb | 4 +--
spec/websocket/driver/client_spec.rb | 48 ++++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 5 deletions(-)
diff --git a/lib/websocket/driver.rb b/lib/websocket/driver.rb
index d568e91..7033a82 100644
--- a/lib/websocket/driver.rb
+++ b/lib/websocket/driver.rb
@@ -42,6 +42,7 @@ module WebSocket
end
MAX_LENGTH = 0x3ffffff
+ PORTS = { 'ws' => 80, 'wss' => 443 }
STATES = [:connecting, :open, :closing, :closed]
BINARY = 'ASCII-8BIT'
@@ -178,6 +179,14 @@ module WebSocket
string.valid_encoding? ? string : nil
end
+ def self.host_header(uri)
+ host = uri.host
+ if uri.port and uri.port != PORTS[uri.scheme]
+ host += ":#{uri.port}"
+ end
+ host
+ end
+
def self.validate_options(options, valid_keys)
options.keys.each do |key|
unless valid_keys.include?(key)
diff --git a/lib/websocket/driver/client.rb b/lib/websocket/driver/client.rb
index 0a45534..68e10eb 100644
--- a/lib/websocket/driver/client.rb
+++ b/lib/websocket/driver/client.rb
@@ -23,11 +23,10 @@ module WebSocket
raise URIError, "#{socket.url} is not a valid WebSocket URL"
end
- host = uri.host + (uri.port ? ":#{uri.port}" : '')
path = (uri.path == '') ? '/' : uri.path
@pathname = path + (uri.query ? '?' + uri.query : '')
- @headers['Host'] = host
+ @headers['Host'] = Driver.host_header(uri)
@headers['Upgrade'] = 'websocket'
@headers['Connection'] = 'Upgrade'
@headers['Sec-WebSocket-Key'] = @key
diff --git a/lib/websocket/driver/proxy.rb b/lib/websocket/driver/proxy.rb
index e4891e3..69f59a5 100644
--- a/lib/websocket/driver/proxy.rb
+++ b/lib/websocket/driver/proxy.rb
@@ -4,8 +4,6 @@ module WebSocket
class Proxy
include EventEmitter
- PORTS = {'ws' => 80, 'wss' => 443}
-
attr_reader :status, :headers
def initialize(client, origin, options)
@@ -20,7 +18,7 @@ module WebSocket
@state = 0
@headers = Headers.new
- @headers['Host'] = @origin.host + (@origin.port ? ":#{@origin.port}" : '')
+ @headers['Host'] = Driver.host_header(@origin)
@headers['Connection'] = 'keep-alive'
@headers['Proxy-Connection'] = 'keep-alive'
diff --git a/spec/websocket/driver/client_spec.rb b/spec/websocket/driver/client_spec.rb
index 75b7f4f..abdde2c 100644
--- a/spec/websocket/driver/client_spec.rb
+++ b/spec/websocket/driver/client_spec.rb
@@ -121,6 +121,54 @@ describe WebSocket::Driver::Client do
end
end
+ describe "with an explicit port" do
+ let(:url) { "ws://www.example.com:3000/socket" }
+
+ it "includes the port in the Host header" do
+ expect(socket).to receive(:write).with(
+ "GET /socket HTTP/1.1\r\n" +
+ "Host: www.example.com:3000\r\n" +
+ "Upgrade: websocket\r\n" +
+ "Connection: Upgrade\r\n" +
+ "Sec-WebSocket-Key: 2vBVWg4Qyk3ZoM/5d3QD9Q==\r\n" +
+ "Sec-WebSocket-Version: 13\r\n" +
+ "\r\n")
+ driver.start
+ end
+ end
+
+ describe "with a wss: URL" do
+ let(:url) { "wss://www.example.com/socket" }
+
+ it "does not include the port in the Host header" do
+ expect(socket).to receive(:write).with(
+ "GET /socket HTTP/1.1\r\n" +
+ "Host: www.example.com\r\n" +
+ "Upgrade: websocket\r\n" +
+ "Connection: Upgrade\r\n" +
+ "Sec-WebSocket-Key: 2vBVWg4Qyk3ZoM/5d3QD9Q==\r\n" +
+ "Sec-WebSocket-Version: 13\r\n" +
+ "\r\n")
+ driver.start
+ end
+ end
+
+ describe "with a wss: URL and explicit port" do
+ let(:url) { "wss://www.example.com:3000/socket" }
+
+ it "includes the port in the Host header" do
+ expect(socket).to receive(:write).with(
+ "GET /socket HTTP/1.1\r\n" +
+ "Host: www.example.com:3000\r\n" +
+ "Upgrade: websocket\r\n" +
+ "Connection: Upgrade\r\n" +
+ "Sec-WebSocket-Key: 2vBVWg4Qyk3ZoM/5d3QD9Q==\r\n" +
+ "Sec-WebSocket-Version: 13\r\n" +
+ "\r\n")
+ driver.start
+ end
+ end
+
describe "with custom headers" do
before do
driver.set_header "User-Agent", "Chrome"
--
2.27.0

View File

@ -1,15 +1,14 @@
%global gem_name websocket-driver %global gem_name websocket-driver
Name: rubygem-%{gem_name} Name: rubygem-%{gem_name}
Version: 0.6.5 Version: 0.7.6
Release: 2 Release: 1
Summary: WebSocket protocol handler with pluggable I/O Summary: WebSocket protocol handler with pluggable I/O
License: MIT License: MIT
URL: http://github.com/faye/websocket-driver-ruby URL: http://github.com/faye/websocket-driver-ruby
Source0: https://rubygems.org/gems/websocket-driver-%{version}.gem Source0: https://rubygems.org/gems/websocket-driver-%{version}.gem
Source1: https://github.com/faye/websocket-driver-ruby/archive/%{version}.tar.gz Source1: https://github.com/faye/websocket-driver-ruby/archive/refs/tags/%{version}.tar.gz
Patch0: Fix-handling-of-default-ports-on-ruby-3.1.patch
BuildRequires: ruby(release) rubygems-devel ruby-devel gcc rubygem(websocket-extensions) BuildRequires: ruby(release) rubygems-devel ruby-devel gcc rubygem(websocket-extensions)
BuildRequires: rubygem(rspec) BuildRequires: rubygem(rspec) rubygem(did_you_mean)
%description %description
This module provides a complete implementation of the WebSocket protocols that This module provides a complete implementation of the WebSocket protocols that
can be hooked up to any TCP library. It aims to simplify things by decoupling can be hooked up to any TCP library. It aims to simplify things by decoupling
@ -47,7 +46,6 @@ pushd .%{gem_instdir}
tar xf %{SOURCE1} tar xf %{SOURCE1}
cd %{gem_name}-ruby-%{version} cd %{gem_name}-ruby-%{version}
sed -i '/bundler/ s/^/#/' spec/spec_helper.rb sed -i '/bundler/ s/^/#/' spec/spec_helper.rb
cat %{PATCH0} | patch -p1
rspec -I$(dirs +1)%{gem_extdir_mri} spec rspec -I$(dirs +1)%{gem_extdir_mri} spec
popd popd
@ -63,9 +61,11 @@ popd
%doc %{gem_docdir} %doc %{gem_docdir}
%doc %{gem_instdir}/CHANGELOG.md %doc %{gem_instdir}/CHANGELOG.md
%doc %{gem_instdir}/README.md %doc %{gem_instdir}/README.md
%{gem_instdir}/examples
%changelog %changelog
* Wed Nov 15 2023 Ge Wang <wang__ge@126.com> - 0.7.6-1
- Update to version 0.7.6
* Tue Jan 17 2023 wulei <wulei80@h-partners.com> - 0.6.5-2 * Tue Jan 17 2023 wulei <wulei80@h-partners.com> - 0.6.5-2
- Fix handling of default ports on Ruby 3.1 - Fix handling of default ports on Ruby 3.1

Binary file not shown.

BIN
websocket-driver-0.7.6.gem Normal file

Binary file not shown.