Skip to content

Commit cc685b4

Browse files
author
Francisco Mejia
committed
Stop setting SERVER_PORT env key if nil
1 parent 16197ef commit cc685b4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/protocol/rack/adapter/generic.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ def unwrap_request(request, env)
106106
if peer = request.peer
107107
env[CGI::REMOTE_ADDR] = peer.ip_address
108108
end
109+
110+
# SERVER_PORT should not be set if it is nil
111+
env.delete(CGI::SERVER_PORT) if env[CGI::SERVER_PORT].nil?
109112
end
110113

111114
def make_environment(request)

test/protocol/rack/adapter/generic.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
expect(env).to have_keys("CONTENT_TYPE" => be == "text/plain")
3636
end
3737
end
38+
39+
with "app server without SERVER_PORT" do
40+
let(:request) do
41+
Protocol::HTTP::Request.new("https", "example.com", "GET", "/", "http/1.1", Protocol::HTTP::Headers[{"accept" => "text/html"}], nil)
42+
end
43+
44+
it "does not include SERVER_PORT in the Rack environment" do
45+
env = adapter.make_environment(request)
46+
47+
expect(env).not.to have_keys(Protocol::Rack::CGI::SERVER_PORT)
48+
end
49+
end
3850

3951
with "a app that returns nil" do
4052
include DisableConsoleContext

0 commit comments

Comments
 (0)