36
36
import org .xnio .ssl .SslConnection ;
37
37
import org .xnio .ssl .XnioSsl ;
38
38
39
- import java .io .IOException ;
40
39
import java .net .InetSocketAddress ;
41
40
import java .net .URI ;
42
41
import java .security .AccessController ;
52
51
*/
53
52
public class HttpClientProvider implements ClientProvider {
54
53
54
+ private static final String HTTP_1_1 = "http/1.1" ;
55
+
55
56
public static final String DISABLE_HTTPS_ENDPOINT_IDENTIFICATION_PROPERTY = "io.undertow.client.https.disableEndpointIdentification" ;
56
57
public static final boolean DISABLE_HTTPS_ENDPOINT_IDENTIFICATION ;
57
58
@@ -154,6 +155,14 @@ public void handleEvent(StreamConnection connection) {
154
155
};
155
156
}
156
157
158
+ public static ALPNClientSelector .ALPNProtocol alpnProtocol (final ClientCallback <ClientConnection > listener , URI uri , ByteBufferPool bufferPool , OptionMap options ) {
159
+ return new ALPNClientSelector .ALPNProtocol (new ChannelListener <SslConnection >() {
160
+ @ Override
161
+ public void handleEvent (SslConnection connection ) {
162
+ listener .completed (new HttpClientConnection (connection , options , bufferPool ));
163
+ }
164
+ }, HTTP_1_1 );
165
+ }
157
166
158
167
private void handleConnected (final StreamConnection connection , final ClientCallback <ClientConnection > listener , final ByteBufferPool bufferPool , final OptionMap options , URI uri ) {
159
168
@@ -163,7 +172,7 @@ private void handleConnected(final StreamConnection connection, final ClientCall
163
172
if (h2 ) {
164
173
protocolList .add (Http2ClientProvider .alpnProtocol (listener , uri , bufferPool , options ));
165
174
}
166
-
175
+ protocolList . add ( alpnProtocol ( listener , uri , bufferPool , options ));
167
176
ALPNClientSelector .runAlpn ((SslConnection ) connection , new ChannelListener <SslConnection >() {
168
177
@ Override
169
178
public void handleEvent (SslConnection connection ) {
@@ -172,11 +181,14 @@ public void handleEvent(SslConnection connection) {
172
181
}, listener , protocolList .toArray (new ALPNClientSelector .ALPNProtocol [protocolList .size ()]));
173
182
} else {
174
183
if (connection instanceof SslConnection ) {
175
- try {
176
- ((SslConnection ) connection ).startHandshake ();
177
- } catch (Throwable t ) {
178
- listener .failed ((t instanceof IOException ) ? (IOException ) t : new IOException (t ));
179
- }
184
+ List <ALPNClientSelector .ALPNProtocol > protocolList = new ArrayList <>();
185
+ protocolList .add (alpnProtocol (listener , uri , bufferPool , options ));
186
+ ALPNClientSelector .runAlpn ((SslConnection ) connection , new ChannelListener <SslConnection >() {
187
+ @ Override
188
+ public void handleEvent (SslConnection connection ) {
189
+ listener .completed (new HttpClientConnection (connection , options , bufferPool ));
190
+ }
191
+ }, listener , protocolList .toArray (new ALPNClientSelector .ALPNProtocol [protocolList .size ()]));
180
192
}
181
193
listener .completed (new HttpClientConnection (connection , options , bufferPool ));
182
194
}
0 commit comments