HttpClient doesn't send HOST header when tunelling HTTP/1.1 through http proxy
Issue
- We confirmed Client HTTP request header but there is not include host header in the request header.
# cat JI9060201.java
import java.net.http.*;
import java.net.*;
import java.io.*;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
public class JI9060201 {
private final static Logger log = Logger.getLogger(JI9060201.class.getName());
static {
try {
LogManager.getLogManager().readConfiguration(new FileInputStream("/etc/tomcat/logging.properties"));
} catch (SecurityException | IOException e1) {
e1.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
var httpResponse = HttpClient.newBuilder()
.proxy(ProxySelector.of(new InetSocketAddress("localhost", 3128)))
.build()
.send(HttpRequest.newBuilder(URI.create("https://www.google.com/"))
.build(), HttpResponse.BodyHandlers.ofString());
assert httpResponse.statusCode() == HttpURLConnection.HTTP_OK;
}
}
#/usr/lib/jvm/java-11-openjdk-11.0.7.10-4.el7_8.x86_64/bin/java JI9060201
#/var/squid/cache.log
..snip..
2020/08/17 04:23:25.235 kid1| 11,2| client_side.cc(2348) parseHttpRequest: HTTP Client REQUEST:
---------
CONNECT www.google.com:443 HTTP/1.1^M
^M
----------
..snip..
Environment
- OpenJDK 11.0.9.11-0 or less
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.