-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unexpected nested query params handling when specifying content-type #427
Comments
Hmm... I'm thinking that introducing |
Hmm actually maybe not, still looking into the best way to do this. |
Hmmm. Not really what a user might expect still. Let's say I have the request with the following set of params: {:method :post
:query-params {:name {:first "Jonh"}}
:form-params {:name {:last "Dow"}}} As we use {:method :post
:content-type :x-www-form-urlencoded
:query-params {:name {:first "Jonh"}}
:form-params {:name {:last "Dow"}}} And I expect it to produce the request in form of
Assume we set {:method :post
:content-type :json
:query-params {:name {:first "Jonh"}}
:form-params {:name {:last "Dow"}}} What I expect is the following:
Note that Right now the library produces different result cause of this branching. It forces appropriate middleware to leave /cc @dakrone |
Okay, I reverted the commits that I had on master to take another look at this. |
This adds the following new parameters: - `:ignore-nested-query-string` :: Do not handle nested query parameters specially, treat them as the exact text they come in as. Defaults to *false*. - `:flatten-nested-form-params` :: Flatten nested (map within a map) `:form-params` before encoding it as the body. Defaults to *false*, meaning form params are encoded only `x-www-form-urlencoded`. - `:flatten-nested-keys` :: An advanced way of specifying which keys having nested maps should be flattened. A middleware function checks the previous two options (`:ignore-nested-query-string` and `:flatten-nested-form-params`) and modifies this to be the list that will be flattened. Resolves #427
@kachayev okay, I thought of a different way to handle this that hopefully works better, can you check out this branch: https://github.com/dakrone/clj-http/compare/nested-param-fix and let me know what you think? (I added documentation so hopefully it's clear enough to follow what was added/changed) |
@dakrone 👍 That works! Fine-grained control is always a good thing. I'm not sure if it's okay to let the user passing contradictory params. Let's say {:ignore-nested-query-string true
:flatten-nested-form-params false
:flatten-nested-keys [:query-params :form-params]} The result might lead to confusion. It's kinda clear enough from the documentation, but maybe it makes sense to throw |
@kachayev that's a good idea, I'll throw an exception if they are both specified. |
* Add options for how to flatten/encode form and query parameters This adds the following new parameters: - `:ignore-nested-query-string` :: Do not handle nested query parameters specially, treat them as the exact text they come in as. Defaults to *false*. - `:flatten-nested-form-params` :: Flatten nested (map within a map) `:form-params` before encoding it as the body. Defaults to *false*, meaning form params are encoded only `x-www-form-urlencoded`. - `:flatten-nested-keys` :: An advanced way of specifying which keys having nested maps should be flattened. A middleware function checks the previous two options (`:ignore-nested-query-string` and `:flatten-nested-form-params`) and modifies this to be the list that will be flattened. Resolves #427 * Add a test for the new middleware * Throw IllegalArgumentException when multiple options are specified
* Add options for how to flatten/encode form and query parameters This adds the following new parameters: - `:ignore-nested-query-string` :: Do not handle nested query parameters specially, treat them as the exact text they come in as. Defaults to *false*. - `:flatten-nested-form-params` :: Flatten nested (map within a map) `:form-params` before encoding it as the body. Defaults to *false*, meaning form params are encoded only `x-www-form-urlencoded`. - `:flatten-nested-keys` :: An advanced way of specifying which keys having nested maps should be flattened. A middleware function checks the previous two options (`:ignore-nested-query-string` and `:flatten-nested-form-params`) and modifies this to be the list that will be flattened. Resolves #427 * Add a test for the new middleware * Throw IllegalArgumentException when multiple options are specified
@dakrone Great, thanks! |
The client handles nester query params properly only in the case when
content-type
is either not given or set to:x-www-form-urlencoded
. Which is unexpected ascontent-type
is intended to be used to determine the content of the body of the request, not the query string in the URL (here and here).Right now:
As expected:
But this:
leads to
Note improper QUERYSTRING value.
Behavior was initially introduced here: 4044f85
Potential fixes/workarounds:
content-type
when packing:query-params
(only:form-params
) - might break someones code:query-string-encoding
to set encoding method for query string directly (independently fromcontent-type
)@dakrone what do you think?
The text was updated successfully, but these errors were encountered: