Skip to content

Commit

Permalink
Proxy support for WebSocket (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Oct 24, 2023
1 parent 507a8ba commit c8c6efb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/main/java/hudson/remoting/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.net.URI;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.security.AccessController;
import java.security.KeyManagementException;
Expand All @@ -53,6 +54,7 @@
import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -692,6 +694,22 @@ public void closeRead() throws IOException {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
if (container instanceof ClientManager) {
ClientManager client = (ClientManager) container;

String proxyHost = System.getProperty("http.proxyHost", System.getenv("proxy_host"));
String proxyPort = System.getProperty("http.proxyPort");
if (proxyHost != null && "http".equals(hudsonUrl.getProtocol()) && NoProxyEvaluator.shouldProxy(hudsonUrl.getHost())) {
URI proxyUri;
if (proxyPort != null) {
proxyUri = URI.create(String.format("http://%s:%s", proxyHost, proxyPort));
} else {
proxyUri = URI.create(String.format("http://%s", proxyHost));
}
client.getProperties().put(ClientProperties.PROXY_URI, proxyUri);
if (proxyCredentials != null) {
client.getProperties().put(ClientProperties.PROXY_HEADERS, Map.of("Proxy-Authorization", "Basic " + Base64.getEncoder().encodeToString(proxyCredentials.getBytes(StandardCharsets.UTF_8))));
}
}

SSLContext sslContext = getSSLContext(candidateCertificates, disableHttpsCertValidation);
if (sslContext != null) {
SslEngineConfigurator sslEngineConfigurator = new SslEngineConfigurator(sslContext);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/hudson/remoting/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ public void setNoCertificateCheck(boolean ignored) throws NoSuchAlgorithmExcepti
"-direct",
"-tunnel",
"-credentials",
"-proxyCredentials",
"-noKeepAlive"
})
public boolean webSocket;
Expand Down

0 comments on commit c8c6efb

Please sign in to comment.