diff --git a/lib/thin/connection.rb b/lib/thin/connection.rb index ec105b8e..d1c78e4b 100644 --- a/lib/thin/connection.rb +++ b/lib/thin/connection.rb @@ -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 diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb index c9aede35..6cc4b6f2 100644 --- a/spec/connection_spec.rb +++ b/spec/connection_spec.rb @@ -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 @@ -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