Copy MockHttpServletRequest changes to spring-web
See gh-24916
This commit is contained in:
parent
6b410df45b
commit
b8835c9f32
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -668,11 +668,14 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
|
||||
@Override
|
||||
public String getServerName() {
|
||||
String host = getHeader(HttpHeaders.HOST);
|
||||
String rawHostHeader = getHeader(HttpHeaders.HOST);
|
||||
String host = rawHostHeader;
|
||||
if (host != null) {
|
||||
host = host.trim();
|
||||
if (host.startsWith("[")) {
|
||||
host = host.substring(1, host.indexOf(']'));
|
||||
int indexOfClosingBracket = host.indexOf(']');
|
||||
Assert.state(indexOfClosingBracket > -1, () -> "Invalid Host header: " + rawHostHeader);
|
||||
host = host.substring(0, indexOfClosingBracket + 1);
|
||||
}
|
||||
else if (host.contains(":")) {
|
||||
host = host.substring(0, host.indexOf(':'));
|
||||
|
|
@ -690,12 +693,15 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
|
||||
@Override
|
||||
public int getServerPort() {
|
||||
String host = getHeader(HttpHeaders.HOST);
|
||||
String rawHostHeader = getHeader(HttpHeaders.HOST);
|
||||
String host = rawHostHeader;
|
||||
if (host != null) {
|
||||
host = host.trim();
|
||||
int idx;
|
||||
if (host.startsWith("[")) {
|
||||
idx = host.indexOf(':', host.indexOf(']'));
|
||||
int indexOfClosingBracket = host.indexOf(']');
|
||||
Assert.state(indexOfClosingBracket > -1, () -> "Invalid Host header: " + rawHostHeader);
|
||||
idx = host.indexOf(':', indexOfClosingBracket);
|
||||
}
|
||||
else {
|
||||
idx = host.indexOf(':');
|
||||
|
|
|
|||
Loading…
Reference in New Issue