Permalink
Browse files

[breaking] params - url-decoding restx path by default.

if you want to keep old behaviour (no decoded path), simply @provide 'restx.http.decode.url.path.params' key with false value
  • Loading branch information...
fcamblor committed Sep 9, 2017
1 parent 46e2ff7 commit ebac25e04f90dc1d9dc3a08f3c26f606ccefda3d
@@ -18,7 +18,7 @@
* Time: 18:38
*/
public abstract class AbstractRequest implements RestxRequest {
private final HttpSettings httpSettings;
protected final HttpSettings httpSettings;
protected AbstractRequest(HttpSettings httpSettings) {
this.httpSettings = httpSettings;
@@ -21,4 +21,8 @@
@SettingsKey(key = "restx.http.gzip.paths", defaultValue = "/{s:.+}")
Collection<String> gzipPaths();
@SettingsKey(key = "restx.http.decode.url.path.params", defaultValue = "true",
doc="Will issue a URLDecoder.decode() on every PATH parameters if true")
boolean decodeURLPathParams();
}
@@ -39,4 +39,9 @@ public HttpSettingsConfig(RestxConfig config) {
return Splitter.on(",").trimResults().splitToList(
config.getString("restx.http.gzip.paths").or("/{s:.+}"));
}
@Override
public boolean decodeURLPathParams() {
return config.getBoolean("restx.http.decode.url.path.params").or(Boolean.TRUE).booleanValue();
}
}
@@ -15,4 +15,7 @@ restx.http.scheme=
# the collection of RESTX paths on which gzip filter should be applied
# to enable it on all resources, use `/{s:.+}`
restx.http.gzip.paths=/{s:.+}
restx.http.gzip.paths=/{s:.+}
# Will issue a URLDecoder.decode() on restx path resolution
restx.http.decode.url.path.params=true
@@ -27,7 +27,7 @@
@Parameterized.Parameters(name="{0}")
public static Iterable<Object[]> data(){
return Arrays.asList(new Object[][]{
{"/v1/v2/35v4/v5", "a=v1 b=v2 c=35 d=v4 e=v5"}
{"/v1/hello%20world/35v4/v5", "a=v1 b=hello world c=35 d=v4 e=v5"},
});
}
@@ -1,6 +1,7 @@
package restx.servlet;
import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.google.common.collect.*;
import restx.AbstractRequest;
import restx.HttpSettings;
@@ -11,6 +12,8 @@
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@@ -48,7 +51,15 @@ protected String getLocalScheme() {
@Override
public String getRestxPath() {
return request.getRequestURI().substring((getBaseApiPath()).length());
String restxPath = request.getRequestURI().substring((getBaseApiPath()).length());
if(this.httpSettings.decodeURLPathParams()) {
try {
restxPath = URLDecoder.decode(restxPath, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw Throwables.propagate(e);
}
}
return restxPath;
}
@Override

0 comments on commit ebac25e

Please sign in to comment.