mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 03:54:33 +02:00
8222527: HttpClient doesn't send HOST header when tunelling HTTP/1.1 through http proxy
HttpClient no longer filters out system host header when sending tunelling CONNECT request to proxy Reviewed-by: michaelm
This commit is contained in:
parent
0d35ef38e6
commit
853da81cfe
6 changed files with 134 additions and 16 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -103,7 +103,8 @@ class Http1Request {
|
|||
HttpClient client = http1Exchange.client();
|
||||
|
||||
// Filter overridable headers from userHeaders
|
||||
userHeaders = HttpHeaders.of(userHeaders.map(), Utils.CONTEXT_RESTRICTED(client));
|
||||
userHeaders = HttpHeaders.of(userHeaders.map(),
|
||||
connection.contextRestricted(request, client));
|
||||
|
||||
final HttpHeaders uh = userHeaders;
|
||||
|
||||
|
|
|
@ -285,6 +285,16 @@ abstract class HttpConnection implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
BiPredicate<String,String> contextRestricted(HttpRequestImpl request, HttpClient client) {
|
||||
if (!isTunnel() && request.isConnect()) {
|
||||
// establishing a proxy tunnel
|
||||
assert request.proxy() == null;
|
||||
return Utils.PROXY_TUNNEL_RESTRICTED(client);
|
||||
} else {
|
||||
return Utils.CONTEXT_RESTRICTED(client);
|
||||
}
|
||||
}
|
||||
|
||||
// Composes a new immutable HttpHeaders that combines the
|
||||
// user and system header but only keeps those headers that
|
||||
// start with "proxy-"
|
||||
|
|
|
@ -178,7 +178,12 @@ public final class Utils {
|
|||
! (k.equalsIgnoreCase("Authorization")
|
||||
&& k.equalsIgnoreCase("Proxy-Authorization"));
|
||||
}
|
||||
private static final BiPredicate<String, String> HOST_RESTRICTED = (k,v) -> !"host".equalsIgnoreCase(k);
|
||||
public static final BiPredicate<String, String> PROXY_TUNNEL_RESTRICTED(HttpClient client) {
|
||||
return CONTEXT_RESTRICTED(client).and(HOST_RESTRICTED);
|
||||
}
|
||||
|
||||
private static final Predicate<String> IS_HOST = "host"::equalsIgnoreCase;
|
||||
private static final Predicate<String> IS_PROXY_HEADER = (k) ->
|
||||
k != null && k.length() > 6 && "proxy-".equalsIgnoreCase(k.substring(0,6));
|
||||
private static final Predicate<String> NO_PROXY_HEADER =
|
||||
|
@ -250,7 +255,8 @@ public final class Utils {
|
|||
|
||||
public static final BiPredicate<String, String> PROXY_TUNNEL_FILTER =
|
||||
(s,v) -> isAllowedForProxy(s, v, PROXY_AUTH_TUNNEL_DISABLED_SCHEMES,
|
||||
IS_PROXY_HEADER);
|
||||
// Allows Proxy-* and Host headers when establishing the tunnel.
|
||||
IS_PROXY_HEADER.or(IS_HOST));
|
||||
public static final BiPredicate<String, String> PROXY_FILTER =
|
||||
(s,v) -> isAllowedForProxy(s, v, PROXY_AUTH_DISABLED_SCHEMES,
|
||||
ALL_HEADERS);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue