!5 Fix build failed due to ruby update to 3.1.3
From: @starlet-dx Reviewed-by: @small_leek Signed-off-by: @small_leek
This commit is contained in:
commit
99c1c0f0e2
171
Ensure-correct-port-is-always-specified.patch
Normal file
171
Ensure-correct-port-is-always-specified.patch
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
From 736a7515aff808a5c268b87066e928b59aed769e Mon Sep 17 00:00:00 2001
|
||||||
|
From: Bernard Potocki <bernard.potocki@imanel.org>
|
||||||
|
Date: Thu, 17 Feb 2022 20:02:21 +0100
|
||||||
|
Subject: [PATCH] Ensure correct port is always specified (#48)
|
||||||
|
|
||||||
|
---
|
||||||
|
CHANGELOG.md | 4 ++++
|
||||||
|
lib/websocket/handshake/base.rb | 18 ++++++++++++++++--
|
||||||
|
lib/websocket/handshake/client.rb | 2 +-
|
||||||
|
lib/websocket/handshake/handler/client04.rb | 2 +-
|
||||||
|
lib/websocket/handshake/handler/client75.rb | 2 +-
|
||||||
|
lib/websocket/handshake/server.rb | 6 +++---
|
||||||
|
spec/support/all_client_drafts.rb | 4 ++++
|
||||||
|
spec/support/all_server_drafts.rb | 8 +++++++-
|
||||||
|
8 files changed, 37 insertions(+), 9 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/CHANGELOG.md b/CHANGELOG.md
|
||||||
|
index d7d2d5d4..e7780000 100644
|
||||||
|
--- a/CHANGELOG.md
|
||||||
|
+++ b/CHANGELOG.md
|
||||||
|
@@ -1,5 +1,9 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
+## Edge
|
||||||
|
+
|
||||||
|
+- ensure correct port is always specified for handshake
|
||||||
|
+
|
||||||
|
## 1.2.9
|
||||||
|
|
||||||
|
- avoid ruby -w warnings
|
||||||
|
diff --git a/lib/websocket/handshake/base.rb b/lib/websocket/handshake/base.rb
|
||||||
|
index 983620a0..274b8fc1 100644
|
||||||
|
--- a/lib/websocket/handshake/base.rb
|
||||||
|
+++ b/lib/websocket/handshake/base.rb
|
||||||
|
@@ -7,7 +7,7 @@ class Base
|
||||||
|
include ExceptionHandler
|
||||||
|
include NiceInspect
|
||||||
|
|
||||||
|
- attr_reader :host, :port, :path, :query,
|
||||||
|
+ attr_reader :host, :path, :query,
|
||||||
|
:state, :version, :secure,
|
||||||
|
:headers, :protocols
|
||||||
|
|
||||||
|
@@ -66,6 +66,20 @@ def leftovers
|
||||||
|
(@leftovers.to_s.split("\n", reserved_leftover_lines + 1)[reserved_leftover_lines] || '').strip
|
||||||
|
end
|
||||||
|
|
||||||
|
+ # Return default port for protocol (80 for ws, 443 for wss)
|
||||||
|
+ def default_port
|
||||||
|
+ secure ? 443 : 80
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
+ # Check if provided port is a default one
|
||||||
|
+ def default_port?
|
||||||
|
+ port == default_port
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
+ def port
|
||||||
|
+ @port || default_port
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
# URI of request.
|
||||||
|
# @return [String] Full URI with protocol
|
||||||
|
# @example
|
||||||
|
@@ -73,7 +87,7 @@ def leftovers
|
||||||
|
def uri
|
||||||
|
uri = String.new(secure ? 'wss://' : 'ws://')
|
||||||
|
uri << host
|
||||||
|
- uri << ":#{port}" if port
|
||||||
|
+ uri << ":#{port}" unless default_port?
|
||||||
|
uri << path
|
||||||
|
uri << "?#{query}" if query
|
||||||
|
uri
|
||||||
|
diff --git a/lib/websocket/handshake/client.rb b/lib/websocket/handshake/client.rb
|
||||||
|
index 437b1790..d1ae0e00 100644
|
||||||
|
--- a/lib/websocket/handshake/client.rb
|
||||||
|
+++ b/lib/websocket/handshake/client.rb
|
||||||
|
@@ -61,7 +61,7 @@ def initialize(args = {})
|
||||||
|
uri = URI.parse(@url || @uri)
|
||||||
|
@secure ||= (uri.scheme == 'wss')
|
||||||
|
@host ||= uri.host
|
||||||
|
- @port ||= uri.port
|
||||||
|
+ @port ||= uri.port || default_port
|
||||||
|
@path ||= uri.path
|
||||||
|
@query ||= uri.query
|
||||||
|
end
|
||||||
|
diff --git a/lib/websocket/handshake/handler/client04.rb b/lib/websocket/handshake/handler/client04.rb
|
||||||
|
index 36e96674..bceb2523 100644
|
||||||
|
--- a/lib/websocket/handshake/handler/client04.rb
|
||||||
|
+++ b/lib/websocket/handshake/handler/client04.rb
|
||||||
|
@@ -21,7 +21,7 @@ def handshake_keys
|
||||||
|
%w[Connection Upgrade]
|
||||||
|
]
|
||||||
|
host = @handshake.host
|
||||||
|
- host += ":#{@handshake.port}" if @handshake.port
|
||||||
|
+ host += ":#{@handshake.port}" unless @handshake.default_port?
|
||||||
|
keys << ['Host', host]
|
||||||
|
keys += super
|
||||||
|
keys << ['Sec-WebSocket-Origin', @handshake.origin] if @handshake.origin
|
||||||
|
diff --git a/lib/websocket/handshake/handler/client75.rb b/lib/websocket/handshake/handler/client75.rb
|
||||||
|
index 228aab53..1eacd68c 100644
|
||||||
|
--- a/lib/websocket/handshake/handler/client75.rb
|
||||||
|
+++ b/lib/websocket/handshake/handler/client75.rb
|
||||||
|
@@ -18,7 +18,7 @@ def handshake_keys
|
||||||
|
%w[Connection Upgrade]
|
||||||
|
]
|
||||||
|
host = @handshake.host
|
||||||
|
- host += ":#{@handshake.port}" if @handshake.port
|
||||||
|
+ host += ":#{@handshake.port}" unless @handshake.default_port?
|
||||||
|
keys << ['Host', host]
|
||||||
|
keys << ['Origin', @handshake.origin] if @handshake.origin
|
||||||
|
keys << ['WebSocket-Protocol', @handshake.protocols.first] if @handshake.protocols.any?
|
||||||
|
diff --git a/lib/websocket/handshake/server.rb b/lib/websocket/handshake/server.rb
|
||||||
|
index 48d3a44c..109ccaaa 100644
|
||||||
|
--- a/lib/websocket/handshake/server.rb
|
||||||
|
+++ b/lib/websocket/handshake/server.rb
|
||||||
|
@@ -129,13 +129,13 @@ def should_respond?
|
||||||
|
# Host of server according to client header
|
||||||
|
# @return [String] host
|
||||||
|
def host
|
||||||
|
- @headers['host'].to_s.split(':')[0].to_s
|
||||||
|
+ @host || @headers['host'].to_s.split(':')[0].to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
# Port of server according to client header
|
||||||
|
- # @return [String] port
|
||||||
|
+ # @return [Integer] port
|
||||||
|
def port
|
||||||
|
- @headers['host'].to_s.split(':')[1]
|
||||||
|
+ (@port || @headers['host'].to_s.split(':')[1] || default_port).to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
diff --git a/spec/support/all_client_drafts.rb b/spec/support/all_client_drafts.rb
|
||||||
|
index d32a6bd2..f032e4b4 100644
|
||||||
|
--- a/spec/support/all_client_drafts.rb
|
||||||
|
+++ b/spec/support/all_client_drafts.rb
|
||||||
|
@@ -38,6 +38,10 @@ def validate_request
|
||||||
|
expect(handshake.query).to eql('aaa=bbb')
|
||||||
|
end
|
||||||
|
|
||||||
|
+ it 'returns default port' do
|
||||||
|
+ expect(handshake.port).to be(80)
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
it 'returns valid port' do
|
||||||
|
@request_params = { port: 123 }
|
||||||
|
expect(handshake.port).to be(123)
|
||||||
|
diff --git a/spec/support/all_server_drafts.rb b/spec/support/all_server_drafts.rb
|
||||||
|
index ccad2cef..dea93b9c 100644
|
||||||
|
--- a/spec/support/all_server_drafts.rb
|
||||||
|
+++ b/spec/support/all_server_drafts.rb
|
||||||
|
@@ -47,11 +47,17 @@ def validate_request
|
||||||
|
expect(handshake.query).to eql('aaa=bbb')
|
||||||
|
end
|
||||||
|
|
||||||
|
+ it 'returns default port' do
|
||||||
|
+ handshake << client_request
|
||||||
|
+
|
||||||
|
+ expect(handshake.port).to be(80)
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
it 'returns valid port' do
|
||||||
|
@request_params = { port: 123 }
|
||||||
|
handshake << client_request
|
||||||
|
|
||||||
|
- expect(handshake.port).to eql('123')
|
||||||
|
+ expect(handshake.port).to be(123)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns valid response' do
|
||||||
@ -1,17 +0,0 @@
|
|||||||
--- spec/support/all_client_drafts.rb.orig 2015-05-07 15:26:54.984167251 -0400
|
|
||||||
+++ spec/support/all_client_drafts.rb 2015-05-07 15:26:58.875133190 -0400
|
|
||||||
@@ -86,10 +86,10 @@ RSpec.shared_examples_for 'all client dr
|
|
||||||
validate_request
|
|
||||||
end
|
|
||||||
|
|
||||||
- it 'should allow custom headers' do
|
|
||||||
- @request_params = { headers: { 'aaa' => 'bbb' } }
|
|
||||||
- validate_request
|
|
||||||
- end
|
|
||||||
+ #it 'should allow custom headers' do
|
|
||||||
+ # @request_params = { headers: { 'aaa' => 'bbb' } }
|
|
||||||
+ # validate_request
|
|
||||||
+ #end
|
|
||||||
|
|
||||||
it 'should recognize unfinished requests' do
|
|
||||||
handshake << server_response[0..-20]
|
|
||||||
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
Name: rubygem-%{gem_name}
|
Name: rubygem-%{gem_name}
|
||||||
Version: 1.2.9
|
Version: 1.2.9
|
||||||
Release: 1
|
Release: 2
|
||||||
Summary: Universal Ruby library to handle WebSocket protocol
|
Summary: Universal Ruby library to handle WebSocket protocol
|
||||||
License: MIT
|
License: MIT
|
||||||
URL: http://github.com/imanel/websocket-ruby
|
URL: http://github.com/imanel/websocket-ruby
|
||||||
Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem
|
Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem
|
||||||
|
Patch0: Ensure-correct-port-is-always-specified.patch
|
||||||
BuildRequires: ruby(release)
|
BuildRequires: ruby(release)
|
||||||
BuildRequires: rubygems-devel
|
BuildRequires: rubygems-devel
|
||||||
BuildRequires: ruby
|
BuildRequires: ruby
|
||||||
@ -26,7 +27,7 @@ BuildArch: noarch
|
|||||||
Documentation for %{name}.
|
Documentation for %{name}.
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup -q -n %{gem_name}-%{version}
|
%autosetup -n %{gem_name}-%{version} -p1
|
||||||
|
|
||||||
%build
|
%build
|
||||||
gem build ../%{gem_name}-%{version}.gemspec
|
gem build ../%{gem_name}-%{version}.gemspec
|
||||||
@ -60,6 +61,9 @@ popd
|
|||||||
%{gem_instdir}/websocket.gemspec
|
%{gem_instdir}/websocket.gemspec
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Jan 17 2023 yaoxin <yaoxin30@h-partners.com> - 1.2.9-2
|
||||||
|
- Fix build failed due to ruby update to 3.1.3
|
||||||
|
|
||||||
* Thu Feb 24 2022 chenchen <chen_aka_jan@163.com> - 1.2.9-1
|
* Thu Feb 24 2022 chenchen <chen_aka_jan@163.com> - 1.2.9-1
|
||||||
- update to 1.2.9
|
- update to 1.2.9
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user