1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Load the configuration before passing it to the binder: (#2897)

* Load the configuration before passing it to the binder:

* Replace unit tests with integration ones
This commit is contained in:
Edouard Chin 2022-08-27 22:38:53 +02:00 committed by GitHub
parent dbf450bdd2
commit de314e47e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 25 deletions

View file

@ -52,17 +52,17 @@ module Puma
@original_argv = @argv.dup
@config = conf
# Advertise the Configuration
Puma.cli_config = @config if defined?(Puma.cli_config)
@config.load
@binder = Binder.new(@log_writer, conf)
@binder.create_inherited_fds(ENV).each { |k| ENV.delete k }
@binder.create_activated_fds(ENV).each { |k| ENV.delete k }
@environment = conf.environment
# Advertise the Configuration
Puma.cli_config = @config if defined?(Puma.cli_config)
@config.load
if @config.options[:bind_to_activated_sockets]
@config.options[:binds] = @binder.synthesize_binds_from_activated_fs(
@config.options[:binds],

View file

@ -0,0 +1 @@
rack_url_scheme "https"

View file

@ -0,0 +1 @@
run lambda { |env| [200, {"Content-Type" => "text/plain"}, [env["rack.url_scheme"]]] }

View file

@ -53,6 +53,28 @@ class TestIntegrationSingle < TestIntegration
assert_equal 0, status
end
def test_rack_url_scheme_default
skip_unless_signal_exist? :TERM
cli_server("test/rackup/url_scheme.ru")
reply = read_body(connect)
stop_server
assert_match("http", reply)
end
def test_conf_is_loaded_before_passing_it_to_binder
skip_unless_signal_exist? :TERM
cli_server("-C test/config/rack_url_scheme.rb test/rackup/url_scheme.ru")
reply = read_body(connect)
stop_server
assert_match("https", reply)
end
def test_prefer_rackup_file_specified_by_cli
skip_unless_signal_exist? :TERM

View file

@ -1368,26 +1368,6 @@ EOF
test_drain_on_shutdown false
end
def test_rack_url_scheme_dflt
server_run
data = send_http_and_read "GET / HTTP/1.0\r\n\r\n"
assert_equal "http", data.split("\r\n").last
end
def test_rack_url_scheme_user
@port = UniquePort.call
opts = { rack_url_scheme: 'user', binds: ["tcp://#{@host}:#{@port}"] }
conf = Puma::Configuration.new(opts).tap(&:clamp)
@server = Puma::Server.new @app, @log_writer, @events, conf.options
@server.inherit_binder Puma::Binder.new(@log_writer, conf)
@server.binder.parse conf.options[:binds], @log_writer
@server.run
data = send_http_and_read "GET / HTTP/1.0\r\n\r\n"
assert_equal "user", data.split("\r\n").last
end
def test_remote_address_header
server_run(remote_address: :header, remote_address_header: 'HTTP_X_REMOTE_IP') do |env|
[200, {}, [env['REMOTE_ADDR']]]