JDK-8287589 : HTTP/2 client doesn't support prior knowledge
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 17.0.1
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2022-05-31
  • Updated: 2022-05-31
Related Reports
Relates :  
It is clearly stated in the JEP 110 that HttpClient:

Must be able to negotiate an upgrade from 1.1 to 2 (or not), **or select 2 from the start**.

HttpClient however seems to do upgrade every time and there is no documented way how to force it to HTTP/2 prior knowledge.
With https the version will be negotiated through ALPN: the client will ask for HTTP/2 and downgrade to HTTP/1.1 if the server doesn't support h2 With plain http the first request will be an upgrade: the request and response headers and request body will go out through HTTP/1.1, but the response body will come back through HTTP/2 if the server accepts the upgrade. Subsequent requests will go through HTTP/2 or HTTP/1.1 depending on whether the server accepted the upgrade to h2c. In the presence of a proxy unsecure connections will all go through HTTP/1.1. Secure connections will go through an SSL tunnel and might use HTTP/1.1 or HTTP/2 depending on which ALPN was negotiated during the establishment of the SSL session - same as with a direct connection. There's no API to force a clear HTTP/2 exchange without an upgrade.