Skip to content

Commit 4638232

Browse files
authored
Support proxy username and password (#2044)
1 parent b6df08a commit 4638232

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ public static class Proxy {
203203

204204
public String host;
205205
public int port = 80;
206+
public String username;
207+
public String password;
206208
}
207209

208210
public static class PreviewConfiguration {

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/httpclient/LazyHttpClient.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class LazyHttpClient implements HttpClient {
6060
public static volatile CountDownLatch safeToInitLatch;
6161
public static volatile String proxyHost;
6262
public static volatile Integer proxyPortNumber;
63+
public static volatile String proxyUsername;
64+
public static volatile String proxyPassword;
6365

6466
public static HttpClient getInstance() {
6567
return INSTANCE;
@@ -109,9 +111,13 @@ private static HttpClient init() {
109111

110112
NettyAsyncHttpClientBuilder builder = new NettyAsyncHttpClientBuilder();
111113
if (proxyHost != null && proxyPortNumber != null) {
112-
builder.proxy(
114+
ProxyOptions proxyOptions =
113115
new ProxyOptions(
114-
ProxyOptions.Type.HTTP, new InetSocketAddress(proxyHost, proxyPortNumber)));
116+
ProxyOptions.Type.HTTP, new InetSocketAddress(proxyHost, proxyPortNumber));
117+
if (proxyUsername != null) {
118+
proxyOptions.setCredentials(proxyUsername, proxyPassword);
119+
}
120+
builder.proxy(proxyOptions);
115121
}
116122
// keeping the thread count to 1 keeps the number of 16mb io.netty.buffer.PoolChunk to 1 also
117123
return builder

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AiComponentInstaller.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ private static AppIdSupplier start(Instrumentation instrumentation) {
154154
if (config.proxy.host != null) {
155155
LazyHttpClient.proxyHost = config.proxy.host;
156156
LazyHttpClient.proxyPortNumber = config.proxy.port;
157+
LazyHttpClient.proxyUsername = config.proxy.username;
158+
LazyHttpClient.proxyPassword = config.proxy.password;
157159
}
158160

159161
List<MetricFilter> metricFilters =

0 commit comments

Comments
 (0)