Implements possibility to disable @Param url encoding#465
Conversation
codefromthecrypt
left a comment
There was a problem hiding this comment.
Mind adding some tests to exemplify this? Also, can you note which api this helps with? (being concrete is always better)
| protected RequestTemplate resolve(Object[] argv, RequestTemplate mutable, | ||
| Map<String, Object> variables) { | ||
| return mutable.resolve(variables); | ||
| final HashMap<String, Boolean> variableToEncoded = new HashMap<String, Boolean>(); |
|
Added one test to exemplify this behaviour and changed HashMap to LinkedHashMap |
codefromthecrypt
left a comment
There was a problem hiding this comment.
some changes, also need to update CHANGES. very close!
ps thanks for the help
| String name = ((Param) annotation).value(); | ||
| checkState(emptyToNull(name) != null, "Param annotation was empty on param %s.", | ||
| paramIndex); | ||
| final Param paramAnnotation = (Param) annotation; |
There was a problem hiding this comment.
nit we don't usually mark locals final unless doing so is notable (ex used in an anonymous type)
| String name = paramAnnotation.value(); | ||
| checkState(emptyToNull(name) != null, "Param annotation was empty on param %s.", paramIndex); | ||
| nameParam(data, name, paramIndex); | ||
| if (annotationType == Param.class) { |
There was a problem hiding this comment.
weird.. we actually checked twice :P
| data.indexToEncoded().put(paramIndex, paramAnnotation.encoded()); | ||
| isHttpAnnotation = true; | ||
| String varName = '{' + name + '}'; | ||
| if (data.template().url().indexOf(varName) == -1 && |
|
|
||
| /** | ||
| * Specifies whether argument is already encoded | ||
| * Value be ignored for headers (headers are never encoded) |
There was a problem hiding this comment.
probably should also put @see QueryMap#encoded as well putting a see link there back to here
| protected RequestTemplate resolve(Object[] argv, RequestTemplate mutable, | ||
| Map<String, Object> variables) { | ||
| return mutable.resolve(variables); | ||
| final Map<String, Boolean> variableToEncoded = new LinkedHashMap<String, Boolean>(); |
There was a problem hiding this comment.
add a comment of what's going on here. (also pls unfinal the locals)
| map.put(key, values); | ||
| } | ||
|
|
||
| public RequestTemplate resolve(Map<String, ?> unencoded) { |
There was a problem hiding this comment.
add see link
ex.
/** like {@link #resolve(Map, Map)}, which assumes no parameter is encoded */| * Replaces query values which are templated with corresponding values from the {@code unencoded} | ||
| * map. Any unresolved queries are removed. | ||
| */ | ||
| public void replaceQueryValues(Map<String, ?> unencoded) { |
There was a problem hiding this comment.
does this break api? if so, please add an overload
| void queryMapWithQueryParams(@Param("name") String name, @QueryMap Map<String, Object> queryMap); | ||
|
|
||
| @RequestLine("GET /?trim={trim}") | ||
| void encodedQueryParam(@Param(value = "trim", encoded = true) String trim); |
| * Replaces query values which are templated with corresponding values from the {@code unencoded} | ||
| * map. Any unresolved queries are removed. | ||
| */ | ||
| public void replaceQueryValues(Map<String, ?> unencoded) { |
There was a problem hiding this comment.
please overload with the prior signature so that we don't break other people's code.
| * map. Any unresolved queries are removed. | ||
| */ | ||
| public void replaceQueryValues(Map<String, ?> unencoded) { | ||
| public void replaceQueryValues(Map<String, ?> unencoded, Map<String, Boolean> alreadyEncoded) { |
There was a problem hiding this comment.
does this need to be public (ex are you using this directly?)
There was a problem hiding this comment.
I see no reason in original method being public either, so I decided to leave overloaded one public too to be consistent.
Should I make new method private instead of overloading public method?
| @@ -1,5 +1,6 @@ | |||
| ### Version 9.3 | |||
| * Adds `FallbackFactory`, allowing access to the cause of a Hystrix fallback | |||
| * Adds support for encoded parameters in @Param via @Param(encoded = true) | |||
There was a problem hiding this comment.
simplify and format? Ex.
- Adds support for encoded parameters via
@Param(encoded = true)
codefromthecrypt
left a comment
There was a problem hiding this comment.
k just some nits, then lets merge this
| @@ -1,5 +1,6 @@ | |||
| ### Version 9.3 | |||
| * Adds `FallbackFactory`, allowing access to the cause of a Hystrix fallback | |||
| * Adds support for encoded parameters via @Param(encoded = true) | |||
There was a problem hiding this comment.
nit, if you get used to doing backticks, not only will the format look nicer, but you won't accidentally mention someone named Param :P
| */ | ||
| public RequestTemplate resolve(Map<String, ?> unencoded) { | ||
| replaceQueryValues(unencoded); | ||
| public RequestTemplate resolve(Map<String, ?> unencoded, Map<String, Boolean> alreadyEncoded) { |
There was a problem hiding this comment.
for this and below, package private is fine (as opposed to private). these are new methods, so we can hide them until someone asks. package private is better as it can be tested directly (plus the bytecode is smaller)
| * Replaces query values which are templated with corresponding values from the {@code unencoded} | ||
| * map. Any unresolved queries are removed. | ||
| */ | ||
| public void replaceQueryValues(Map<String, ?> unencoded) { |
| * map. Any unresolved queries are removed. | ||
| */ | ||
| public void replaceQueryValues(Map<String, ?> unencoded) { | ||
| public void replaceQueryValues(Map<String, ?> unencoded, Map<String, Boolean> alreadyEncoded) { |
Now it is possible with @Param(encoded = true) to disable hardcoded call of urlEncode method on every @Param
This helps to implement matrix params or send unencoded path variables or query parameters which is required by some APIs