Skip to content

Commit

Permalink
[UNDERTOW-2347] Always specify at least http/1.1 in application_layer…
Browse files Browse the repository at this point in the history
…_protocol_negotiation ALPN extension when doing TLS
  • Loading branch information
ropalka authored and fl4via committed Apr 19, 2024
1 parent 607cf7f commit eeed7e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 19 additions & 7 deletions core/src/main/java/io/undertow/client/http/HttpClientProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.xnio.ssl.SslConnection;
import org.xnio.ssl.XnioSsl;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.AccessController;
Expand All @@ -52,6 +51,8 @@
*/
public class HttpClientProvider implements ClientProvider {

private static final String HTTP_1_1 = "http/1.1";

public static final String DISABLE_HTTPS_ENDPOINT_IDENTIFICATION_PROPERTY = "io.undertow.client.https.disableEndpointIdentification";
public static final boolean DISABLE_HTTPS_ENDPOINT_IDENTIFICATION;

Expand Down Expand Up @@ -154,6 +155,14 @@ public void handleEvent(StreamConnection connection) {
};
}

public static ALPNClientSelector.ALPNProtocol alpnProtocol(final ClientCallback<ClientConnection> listener, URI uri, ByteBufferPool bufferPool, OptionMap options) {
return new ALPNClientSelector.ALPNProtocol(new ChannelListener<SslConnection>() {
@Override
public void handleEvent(SslConnection connection) {
listener.completed(new HttpClientConnection(connection, options, bufferPool));
}
}, HTTP_1_1);
}

private void handleConnected(final StreamConnection connection, final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, URI uri) {

Expand All @@ -163,7 +172,7 @@ private void handleConnected(final StreamConnection connection, final ClientCall
if(h2) {
protocolList.add(Http2ClientProvider.alpnProtocol(listener, uri, bufferPool, options));
}

protocolList.add(alpnProtocol(listener, uri, bufferPool, options));
ALPNClientSelector.runAlpn((SslConnection) connection, new ChannelListener<SslConnection>() {
@Override
public void handleEvent(SslConnection connection) {
Expand All @@ -172,11 +181,14 @@ public void handleEvent(SslConnection connection) {
}, listener, protocolList.toArray(new ALPNClientSelector.ALPNProtocol[protocolList.size()]));
} else {
if(connection instanceof SslConnection) {
try {
((SslConnection) connection).startHandshake();
} catch (Throwable t) {
listener.failed((t instanceof IOException) ? (IOException) t : new IOException(t));
}
List<ALPNClientSelector.ALPNProtocol> protocolList = new ArrayList<>();
protocolList.add(alpnProtocol(listener, uri, bufferPool, options));
ALPNClientSelector.runAlpn((SslConnection) connection, new ChannelListener<SslConnection>() {
@Override
public void handleEvent(SslConnection connection) {
listener.completed(new HttpClientConnection(connection, options, bufferPool));
}
}, listener, protocolList.toArray(new ALPNClientSelector.ALPNProtocol[protocolList.size()]));
}
listener.completed(new HttpClientConnection(connection, options, bufferPool));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
public class Http2ClientProvider implements ClientProvider {

private static final String HTTP2 = "h2";
private static final String HTTP_1_1 = "http/1.1";

private static final ChannelListener<SslConnection> FAILED = new ChannelListener<SslConnection>() {
@Override
public void handleEvent(SslConnection connection) {
Expand Down

0 comments on commit eeed7e4

Please sign in to comment.