Duplicate :
|
|
Relates :
|
|
Relates :
|
A DESCRIPTION OF THE PROBLEM : Setting socket options for HttpURLConnection or HttpClient is a necessity for some workloads. For instance, if you're doing HTTP 1.1 streaming with `setChunkedStreamingMode` then for performance reasons you likely want to disable Nagle's algorithm by setting the `TCP_NODELAY` on the sending side. For an HTTP connection (not HTTPS because there's `setSSLSocketFactory` for that), this is only possible by setting `Socket.setSocketImplFactory(SocketImplFactory fac)` application-wide. However, JDK-8261228 deprecates and this and JDK-8235139 says it wants to eventually remove this functionality. The only other way to change HttpURLConnection socket options is using reflection, which is risky because it's going beyond the public API. Proposal: Create a system property to enable TCP_NODELAY on the HTTP client socket similiar to what jdk.httpserver has with `sun.net.httpserver.nodelay` OR give HttpURLConnection a `setSocketFactory` method similar to what HttpsURLConnection has (and the equivalent for HttpClient) Also, HTTP 1.1 streaming (e.g. with HttpURLConnection `setChunkedStreamingMode`) should default to using `TCP_NODELAY`. It would be great for Java to give the programmer more ability to configure the underlying socket. Apache's HttpClient provides direct access to the socket so you can optimize as you see fit. However, I understand it may be undesirable to expose those details to the public interface. I've also read that web browsers set `TCP_NODELAY` by default for web sockets, and other languages enable TCP_NODELAY by default in some cases. https://bugs.openjdk.org/browse/JDK-8235139 https://bugs.openjdk.org/browse/JDK-8261228 https://docs.oracle.com/javase/8/docs/api/java/net/class-use/SocketImplFactory.html Thank you.
|