MockHttpServletRequest.getRequestURL aligns with getServerName/Port

Issue: SPR-16138
This commit is contained in:
Juergen Hoeller
2017-11-05 16:11:21 +01:00
parent db050ac38c
commit 0edf4d6509
3 changed files with 60 additions and 33 deletions

View File

@@ -1199,13 +1199,18 @@ public class MockHttpServletRequest implements HttpServletRequest {
@Override
public StringBuffer getRequestURL() {
StringBuffer url = new StringBuffer(this.scheme).append("://").append(this.serverName);
if (this.serverPort > 0 && ((HTTP.equalsIgnoreCase(this.scheme) && this.serverPort != 80) ||
(HTTPS.equalsIgnoreCase(this.scheme) && this.serverPort != 443))) {
url.append(':').append(this.serverPort);
String scheme = getScheme();
String server = getServerName();
int port = getServerPort();
String uri = getRequestURI();
StringBuffer url = new StringBuffer(scheme).append("://").append(server);
if (port > 0 && ((HTTP.equalsIgnoreCase(scheme) && port != 80) ||
(HTTPS.equalsIgnoreCase(scheme) && port != 443))) {
url.append(':').append(port);
}
if (StringUtils.hasText(getRequestURI())) {
url.append(getRequestURI());
if (StringUtils.hasText(uri)) {
url.append(uri);
}
return url;
}
@@ -1318,12 +1323,12 @@ public class MockHttpServletRequest implements HttpServletRequest {
@Override
@Nullable
public Part getPart(String name) throws IOException, IllegalStateException, ServletException {
public Part getPart(String name) throws IOException, ServletException {
return this.parts.getFirst(name);
}
@Override
public Collection<Part> getParts() throws IOException, IllegalStateException, ServletException {
public Collection<Part> getParts() throws IOException, ServletException {
List<Part> result = new LinkedList<>();
for (List<Part> list : this.parts.values()) {
result.addAll(list);