|
35 | 35 | public class DefaultSslEngineFactory extends SslEngineFactoryBase { |
36 | 36 |
|
37 | 37 | private volatile SslContext sslContext; |
38 | | - // WebSocket connections use a context that advertises only http/1.1 in ALPN: AsyncHttpClient does not |
39 | | - // implement RFC 8441 (WebSocket over HTTP/2), so the server must not be able to negotiate h2 for them. |
| 38 | + // Connections that must stay on HTTP/1.1 use a context that advertises only http/1.1 in ALPN: WebSocket, |
| 39 | + // because AsyncHttpClient does not implement RFC 8441 (WebSocket over HTTP/2), and the hop to an HTTPS |
| 40 | + // proxy, which only ever carries an HTTP/1.1 CONNECT or absolute-URI request. |
40 | 41 | private volatile SslContext http1OnlySslContext; |
41 | 42 |
|
42 | 43 | private SslContext buildSslContext(AsyncHttpClientConfig config, boolean http2Allowed) throws SSLException { |
@@ -98,16 +99,19 @@ public SSLEngine newSslEngine(AsyncHttpClientConfig config, String peerHost, int |
98 | 99 | } |
99 | 100 |
|
100 | 101 | /** |
101 | | - * Returns the context for a WebSocket connection, which must advertise only http/1.1 (AsyncHttpClient does |
102 | | - * not implement RFC 8441, WebSocket over HTTP/2). Built lazily and cached on first use so a client that |
103 | | - * never opens a {@code wss://} connection never pays for a second {@link SslContext}. |
| 102 | + * Returns the context for a connection that must stay on HTTP/1.1 and therefore advertise only http/1.1: |
| 103 | + * a WebSocket connection (AsyncHttpClient does not implement RFC 8441, WebSocket over HTTP/2), and the hop |
| 104 | + * to an HTTPS proxy (that hop only ever carries an HTTP/1.1 {@code CONNECT} or absolute-URI request). |
| 105 | + * Built lazily and cached on first use so a client that never opens such a connection never pays for a |
| 106 | + * second {@link SslContext}. |
104 | 107 | * <p> |
105 | 108 | * Only a self-built, h2-enabled context advertises h2 and therefore needs a separate http/1.1-only variant; |
106 | 109 | * a user-supplied context or an h2-disabled one already negotiates http/1.1, so it is reused (which also |
107 | 110 | * avoids double-releasing it in {@link #destroy()}). <strong>Note:</strong> a user-supplied |
108 | 111 | * {@link AsyncHttpClientConfig#getSslContext()} is used as-is for every connection type — if it advertises |
109 | | - * h2 in ALPN, a {@code wss://} connection may still negotiate h2, which AHC cannot speak for WebSocket. A |
110 | | - * caller needing WebSocket with a custom context must supply one that negotiates http/1.1. |
| 112 | + * h2 in ALPN, a {@code wss://} connection or an HTTPS-proxy connection may still negotiate h2, which AHC |
| 113 | + * cannot speak on either. A caller needing those with a custom context must supply one that negotiates |
| 114 | + * http/1.1. |
111 | 115 | */ |
112 | 116 | private SslContext http1OnlySslContext(AsyncHttpClientConfig config) { |
113 | 117 | SslContext ctx = http1OnlySslContext; |
|
0 commit comments