Skip to content

Commit b428f6c

Browse files
authored
Ensure SERVER_PORT is correct when using SSL (#397)
1 parent 85b956c commit b428f6c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/thin/connection.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ def pre_process
7272
if @backend.ssl?
7373
@request.env["rack.url_scheme"] = "https"
7474

75+
if @backend.respond_to?(:port)
76+
@request.env['SERVER_PORT'] = @backend.port.to_s
77+
end
78+
7579
if cert = get_peer_cert
7680
@request.env['rack.peer_cert'] = cert
7781
end

spec/connection_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
expect(@connection.remote_address).to eq("127.0.0.1")
7979
end
8080

81-
it "should return nil on error retreiving remote_address" do
81+
it "should return nil on error retrieving remote_address" do
8282
allow(@connection).to receive(:get_peername).and_raise(RuntimeError)
8383
expect(@connection.remote_address).to be_nil
8484
end
@@ -143,4 +143,12 @@
143143
it "should not set as threaded when app do not respond to deferred?" do
144144
expect(@connection).not_to be_threaded
145145
end
146+
147+
it "should have correct SERVER_PORT when using ssl" do
148+
@connection.backend = double("backend", :ssl? => true, :port => 443)
149+
150+
@connection.process
151+
152+
expect(@connection.request.env["SERVER_PORT"]).to eq("443")
153+
end
146154
end

0 commit comments

Comments
 (0)