Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rack::Request headers usage. #1880

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rack/common_logger.rb
Expand Up @@ -54,18 +54,18 @@ def log(env, status, response_headers, began_at)

msg = FORMAT % [
request.ip || "-",
request.get_header("REMOTE_USER") || "-",
request.env['REMOTE_USER'] || "-",
Time.now.strftime("%d/%b/%Y:%H:%M:%S %z"),
request.request_method,
request.script_name,
request.path_info,
request.query_string.empty? ? "" : "?#{request.query_string}",
request.get_header(SERVER_PROTOCOL),
request.env[SERVER_PROTOCOL],
status.to_s[0..3],
length,
Utils.clock_time - began_at ]

logger = @logger || request.get_header(RACK_ERRORS)
logger = @logger || request.env[RACK_ERRORS]
# Standard library logger doesn't support write but it supports << which actually
# calls to write on the log device without formatting
if logger.respond_to?(:write)
Expand Down
4 changes: 2 additions & 2 deletions lib/rack/files.rb
Expand Up @@ -78,7 +78,7 @@ def serving(request, path)
return [200, { 'allow' => ALLOW_HEADER, CONTENT_LENGTH => '0' }, []]
end
last_modified = ::File.mtime(path).httpdate
return [304, {}, []] if request.get_header('HTTP_IF_MODIFIED_SINCE') == last_modified
return [304, {}, []] if request.get_header('if-modified-since') == last_modified

headers = { "last-modified" => last_modified }
mime_type = mime_type path, @default_mime
Expand All @@ -90,7 +90,7 @@ def serving(request, path)
status = 200
size = filesize path

ranges = Rack::Utils.get_byte_ranges(request.get_header('HTTP_RANGE'), size)
ranges = Rack::Utils.get_byte_ranges(request.get_header('range'), size)
if ranges.nil?
# No ranges:
ranges = [0..size - 1]
Expand Down
4 changes: 2 additions & 2 deletions lib/rack/method_override.rb
Expand Up @@ -48,9 +48,9 @@ def allowed_methods
def method_override_param(req)
req.POST[METHOD_OVERRIDE_PARAM_KEY]
rescue Utils::InvalidParameterError, Utils::ParameterTypeError
req.get_header(RACK_ERRORS).puts "Invalid or incomplete POST params"
req.env[RACK_ERRORS].puts "Invalid or incomplete POST params"
rescue EOFError
req.get_header(RACK_ERRORS).puts "Bad request content body"
req.env[RACK_ERRORS].puts "Bad request content body"
end
end
end