Merge "Merge branch 'stable-2.14'"
This commit is contained in:
@@ -14,9 +14,13 @@
|
|||||||
|
|
||||||
package com.google.gerrit.httpd;
|
package com.google.gerrit.httpd;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class CanonicalWebUrl {
|
public class CanonicalWebUrl {
|
||||||
@@ -35,10 +39,15 @@ public class CanonicalWebUrl {
|
|||||||
|
|
||||||
static String computeFromRequest(HttpServletRequest req) {
|
static String computeFromRequest(HttpServletRequest req) {
|
||||||
StringBuffer url = req.getRequestURL();
|
StringBuffer url = req.getRequestURL();
|
||||||
url.setLength(url.length() - req.getServletPath().length());
|
try {
|
||||||
if (url.charAt(url.length() - 1) != '/') {
|
url = new StringBuffer(URLDecoder.decode(url.toString(), UTF_8.name()));
|
||||||
url.append('/');
|
url.setLength(url.length() - req.getServletPath().length());
|
||||||
|
if (url.charAt(url.length() - 1) != '/') {
|
||||||
|
url.append('/');
|
||||||
|
}
|
||||||
|
return url.toString();
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new IllegalStateException("Unsupported encoding for request URL " + url, e);
|
||||||
}
|
}
|
||||||
return url.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user