Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8338681

Socket Options for HTTP Client After Recent Deprecation/Removal

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Java 17+

      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 latency 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 interface.

      Proposal: Give HttpURLConnection a `setSocketFactory` similar to what HttpsURLConnection has (and the equivalent for HttpClient) OR make the `TCP_NODELAY` socket option the deafult for `setChunkedStreamingMode`.

      Probably the first option would be most flexible in case there's other socket options a programmer needs wants set. Apache's HttpClient gives you 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 similar.

      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



            michaelm Michael McMahon
            pnarayanaswa Praveen Narayanaswamy
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: