Skip to content

Commit

Permalink
Ensure SERVER_PORT is correct when using SSL (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikt9 authored Nov 8, 2023
1 parent 85b956c commit b428f6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/thin/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def pre_process
if @backend.ssl?
@request.env["rack.url_scheme"] = "https"

if @backend.respond_to?(:port)
@request.env['SERVER_PORT'] = @backend.port.to_s
end

if cert = get_peer_cert
@request.env['rack.peer_cert'] = cert
end
Expand Down
10 changes: 9 additions & 1 deletion spec/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
expect(@connection.remote_address).to eq("127.0.0.1")
end

it "should return nil on error retreiving remote_address" do
it "should return nil on error retrieving remote_address" do
allow(@connection).to receive(:get_peername).and_raise(RuntimeError)
expect(@connection.remote_address).to be_nil
end
Expand Down Expand Up @@ -143,4 +143,12 @@
it "should not set as threaded when app do not respond to deferred?" do
expect(@connection).not_to be_threaded
end

it "should have correct SERVER_PORT when using ssl" do
@connection.backend = double("backend", :ssl? => true, :port => 443)

@connection.process

expect(@connection.request.env["SERVER_PORT"]).to eq("443")
end
end

0 comments on commit b428f6c

Please sign in to comment.