From de870595d07da20291c410cf064ff79a16f00826 Mon Sep 17 00:00:00 2001 From: Jackson Ray Hamilton Date: Fri, 7 Apr 2017 09:42:01 -0700 Subject: [PATCH] Ensure env[QUERY_STRING] is not set to nil when there is no query. (#1259) * Ensure env[QUERY_STRING] is not set to nil when there is no query. In my application, sending a request like "GET http://example.dev:20557/ HTTP/1.1" would cause "Rack::Lint::LintError: env variable QUERY_STRING has non-string value nil" and eventually "Read error: #", due to there being no query string in the "full host request header." * Explain why we should only set a non-nil env value. --- lib/puma/server.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/puma/server.rb b/lib/puma/server.rb index 17290117..4c102b3e 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -522,7 +522,9 @@ module Puma raise "No REQUEST PATH" unless env[REQUEST_PATH] - env[QUERY_STRING] = uri.query + # A nil env value will cause a LintError (and fatal errors elsewhere), + # so only set the env value if there actually is a value. + env[QUERY_STRING] = uri.query if uri.query end env[PATH_INFO] = env[REQUEST_PATH]