Support ipV6 Host addresses in HttpHeaders
This commit parses the "Host" HTTP request header as an `InetSocketAddress`, while supporting IPv6 addresses like `[::1]`. This host string contains `:` chars even though it has no port information. Issue: SPR-15799
This commit is contained in:
parent
bb684ce60b
commit
f1abcba4eb
|
@ -971,7 +971,12 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
|||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
int idx = value.lastIndexOf(':');
|
||||
final int idx;
|
||||
if (value.startsWith("[")) {
|
||||
idx = value.indexOf(':', value.indexOf(']'));
|
||||
} else {
|
||||
idx = value.lastIndexOf(':');
|
||||
}
|
||||
String hostname = null;
|
||||
int port = 0;
|
||||
if (idx != -1 && idx < value.length() - 1) {
|
||||
|
|
|
@ -168,6 +168,14 @@ public class HttpHeadersTests {
|
|||
assertEquals("Invalid Host header", "localhost", headers.getFirst("Host"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv6Host() {
|
||||
InetSocketAddress host = InetSocketAddress.createUnresolved("[::1]", 0);
|
||||
headers.setHost(host);
|
||||
assertEquals("Invalid Host header", host, headers.getHost());
|
||||
assertEquals("Invalid Host header", "[::1]", headers.getFirst("Host"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void illegalETag() {
|
||||
String eTag = "v2.6";
|
||||
|
|
Loading…
Reference in New Issue