-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
It's not easy to use the proposed interface for query parameters. #2053
Comments
I've made some local changes so the following is possible: if Rack.release >= "3"
class QueryParser < ::Rack::QueryParser
def missing_value
nil
end
end
QUERY_PARSER = QueryParser.make_default(32)
def query_parser
QUERY_PARSER
end
def query_hash_key
"action_dispatch.request.query_hash"
end
def form_hash_key
"action_dispatch.request.form_hash"
end
end But, I still can't get the tests to pass. |
Yeah, I've been staring at this this evening, and pondering the fact that Rails effectively needs to fully override The ISTM the ideal model might be that the Another possibility, which I pondered even just looking at the similar patterns across As-is, I think Rails needs to: # Returns the data received in the query string.
def GET
if get_header(RAILS_REQUEST_QUERY_STRING) == query_string
if query_hash = get_header(RAILS_REQUEST_QUERY_HASH)
return query_hash
end
end
set_header RAILS_REQUEST_QUERY_STRING, query_string
set_header(RAILS_REQUEST_QUERY_HASH, expand_params(query_param_list))
end With a helper, that might be: # Returns the data received in the query string.
def GET
cache_in_env(RAILS_REQUEST_QUERY_HASH, RAILS_REQUEST_QUERY_STRING, query_string) do
expand_params(query_param_list)
end
end
# where:
def cache_in_env(cache_key, validity_key, current_input, &block)
if get_header(validity_key) == current_input
if cached_value = get_header(cache_key)
return cached_value
end
end
set_header validity_key, current_input
set_header(cache_key, block.call(current_input))
end Obviously anything that means "overriding (all above code is untested hand-waving, to be clear) |
I found the problem. def env_for(uri, env)
env = DEFAULT_ENV.merge(@env).merge!(env)
env['HTTP_HOST'] ||= [uri.host, (uri.port if uri.port != uri.default_port)].compact.join(':')
env['HTTPS'] = 'on' if URI::HTTPS === uri
env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' if env[:xhr]
env['REQUEST_METHOD'] ||= env[:method] ? env[:method].to_s.upcase : 'GET'
params = env.delete(:params)
query_array = [uri.query]
if env['REQUEST_METHOD'] == 'GET'
# Treat params as query params
if params
append_query_params(query_array, params)
end This code, appears to convert It essentially seems like |
I'm going to be honest, I really dislike this extra complexity, but I'm at a loss as to how it could be better. I feel like we are kind of painted into a corner. It feels like the Rails way of doing things is really at odds with the way everything else works and it's creating a ton of friction. Adding keys for the fields that are per-class makes sense to me, as an option. |
# Append a string version of the query params to the array of query params.
def append_query_params(query_array, query_params)
query_params = parse_nested_query(query_params) if query_params.is_a?(String)
query_array << build_nested_query(query_params)
end |
rails/rails#47652 includes some changes to the test runner to bypass |
I'm assuming you want to include the |
@ioquatix Can this be closed? |
Are we still willing to entertain deprecating |
I'm still on board for deprecating that. I thought this issue was related to the |
As I proposed a while ago, I think |
Rails sub-classes this, and calls
super
indef GET
.Even if a sub-class overrides
expand_params
, it's cached into the same key.Therefore, the previous call to
Rack::Request#GET
caches the value ofexpand_params
, and the later invocation ofMyCustomRequest#GET
may reuse the same cache even with differentexpand_params
behaviour.Additionally, setting
set_header RACK_REQUEST_QUERY_HASH, nil
won't triggerif query_hash = get_header(RACK_REQUEST_QUERY_HASH)
later, so I'm not sure if that's supposed to be cached. I suggest we keep manipulation ofRACK_REQUEST_QUERY_HASH
out ofquery_param_list
.Rails PR: rails/rails#47652
cc @matthewd
The text was updated successfully, but these errors were encountered: