lib/rack/request.rb in rack-3.0.10 vs lib/rack/request.rb in rack-3.1.0
- old
+ new
@@ -480,13 +480,18 @@
PARSEABLE_DATA_MEDIA_TYPES.include?(media_type)
end
# Returns the data received in the query string.
def GET
- if get_header(RACK_REQUEST_QUERY_STRING) == query_string
+ rr_query_string = get_header(RACK_REQUEST_QUERY_STRING)
+ query_string = self.query_string
+ if rr_query_string == query_string
get_header(RACK_REQUEST_QUERY_HASH)
else
+ if rr_query_string
+ warn "query string used for GET parsing different from current query string. Starting in Rack 3.2, Rack will used the cached GET value instead of parsing the current query string.", uplevel: 1
+ end
query_hash = parse_query(query_string, '&')
set_header(RACK_REQUEST_QUERY_STRING, query_string)
set_header(RACK_REQUEST_QUERY_HASH, query_hash)
end
end
@@ -503,22 +508,28 @@
begin
rack_input = get_header(RACK_INPUT)
# If the form hash was already memoized:
if form_hash = get_header(RACK_REQUEST_FORM_HASH)
+ form_input = get_header(RACK_REQUEST_FORM_INPUT)
# And it was memoized from the same input:
- if get_header(RACK_REQUEST_FORM_INPUT).equal?(rack_input)
+ if form_input.equal?(rack_input)
return form_hash
+ elsif form_input
+ warn "input stream used for POST parsing different from current input stream. Starting in Rack 3.2, Rack will used the cached POST value instead of parsing the current input stream.", uplevel: 1
end
end
# Otherwise, figure out how to parse the input:
if rack_input.nil?
set_header RACK_REQUEST_FORM_INPUT, nil
set_header(RACK_REQUEST_FORM_HASH, {})
elsif form_data? || parseable_data?
- unless set_header(RACK_REQUEST_FORM_HASH, parse_multipart)
+ if pairs = Rack::Multipart.parse_multipart(env, Rack::Multipart::ParamList)
+ set_header RACK_REQUEST_FORM_PAIRS, pairs
+ set_header RACK_REQUEST_FORM_HASH, expand_param_pairs(pairs)
+ else
form_vars = get_header(RACK_INPUT).read
# Fix for Safari Ajax postings that always append \0
# form_vars.sub!(/\0\z/, '') # performance replacement:
form_vars.slice!(-1) if form_vars.end_with?("\0")
@@ -603,28 +614,14 @@
def trusted_proxy?(ip)
Rack::Request.ip_filter.call(ip)
end
- # shortcut for <tt>request.params[key]</tt>
- def [](key)
- warn("Request#[] is deprecated and will be removed in a future version of Rack. Please use request.params[] instead", uplevel: 1)
-
- params[key.to_s]
- end
-
- # shortcut for <tt>request.params[key] = value</tt>
- #
- # Note that modifications will not be persisted in the env. Use update_param or delete_param if you want to destructively modify params.
- def []=(key, value)
- warn("Request#[]= is deprecated and will be removed in a future version of Rack. Please use request.params[]= instead", uplevel: 1)
-
- params[key.to_s] = value
- end
-
# like Hash#values_at
def values_at(*keys)
+ warn("Request#values_at is deprecated and will be removed in a future version of Rack. Please use request.params.values_at instead", uplevel: 1)
+
keys.map { |key| params[key] }
end
private
@@ -643,12 +640,12 @@
host
end
end
def parse_http_accept_header(header)
- header.to_s.split(",").each(&:strip!).map do |part|
- attribute, parameters = part.split(";", 2).each(&:strip!)
+ header.to_s.split(/\s*,\s*/).map do |part|
+ attribute, parameters = part.split(/\s*;\s*/, 2)
quality = 1.0
if parameters and /\Aq=([\d.]+)/ =~ parameters
quality = $1.to_f
end
[attribute, quality]
@@ -668,9 +665,19 @@
query_parser.parse_nested_query(qs, d)
end
def parse_multipart
Rack::Multipart.extract_multipart(self, query_parser)
+ end
+
+ def expand_param_pairs(pairs, query_parser = query_parser())
+ params = query_parser.make_params
+
+ pairs.each do |k, v|
+ query_parser.normalize_params(params, k, v)
+ end
+
+ params.to_params_hash
end
def split_header(value)
value ? value.strip.split(/[,\s]+/) : []
end