1
1
package com .launchdarkly .client ;
2
2
3
+ import org .apache .http .HttpHost ;
3
4
import org .apache .http .client .methods .HttpGet ;
4
5
import org .apache .http .client .methods .HttpPost ;
5
6
import org .apache .http .client .utils .URIBuilder ;
@@ -27,13 +28,15 @@ public final class LDConfig {
27
28
final int connectTimeout ;
28
29
final int socketTimeout ;
29
30
final int flushInterval ;
31
+ final HttpHost proxyHost ;
30
32
31
33
protected LDConfig (Builder builder ) {
32
34
this .baseURI = builder .baseURI ;
33
35
this .capacity = builder .capacity ;
34
36
this .connectTimeout = builder .connectTimeout ;
35
37
this .socketTimeout = builder .socketTimeout ;
36
38
this .flushInterval = builder .flushInterval ;
39
+ this .proxyHost = builder .proxyHost ();
37
40
}
38
41
39
42
/**
@@ -54,6 +57,9 @@ public static class Builder{
54
57
private int socketTimeout = DEFAULT_SOCKET_TIMEOUT ;
55
58
private int capacity = DEFAULT_CAPACITY ;
56
59
private int flushInterval = DEFAULT_FLUSH_INTERVAL ;
60
+ private String proxyHost ;
61
+ private int proxyPort = -1 ;
62
+ private String proxyScheme ;
57
63
58
64
/**
59
65
* Creates a builder with all configuration parameters set to the default
@@ -151,6 +157,63 @@ public Builder capacity(int capacity) {
151
157
return this ;
152
158
}
153
159
160
+ /**
161
+ * Set the host to use as an HTTP proxy for making connections to LaunchDarkly. If this is not set, but
162
+ * {@link #proxyPort(int)} or {@link #proxyScheme(String)} are specified, this will default to <code>localhost</code>.
163
+ * <p>
164
+ * If none of {@link #proxyHost(String)}, {@link #proxyPort(int)} or {@link #proxyScheme(String)} are specified,
165
+ * a proxy will not be used, and {@link LDClient} will connect to LaunchDarkly directly.
166
+ * </p>
167
+ * @param host
168
+ * @return
169
+ */
170
+ public Builder proxyHost (String host ) {
171
+ this .proxyHost = host ;
172
+ return this ;
173
+ }
174
+
175
+ /**
176
+ * Set the port to use for an HTTP proxy for making connections to LaunchDarkly. If not set (but {@link #proxyHost(String)}
177
+ * or {@link #proxyScheme(String)} are specified, the default port for the scheme will be used.
178
+ *
179
+ * <p>
180
+ * If none of {@link #proxyHost(String)}, {@link #proxyPort(int)} or {@link #proxyScheme(String)} are specified,
181
+ * a proxy will not be used, and {@link LDClient} will connect to LaunchDarkly directly.
182
+ * </p>
183
+ * @param port
184
+ * @return
185
+ */
186
+ public Builder proxyPort (int port ) {
187
+ this .proxyPort = port ;
188
+ return this ;
189
+ }
190
+
191
+ /**
192
+ * Set the scheme to use for an HTTP proxy for making connections to LaunchDarkly. If not set (but {@link #proxyHost(String)}
193
+ * or {@link #proxyPort(int)} are specified, the default <code>https</code> scheme will be used.
194
+ *
195
+ * <p>
196
+ * If none of {@link #proxyHost(String)}, {@link #proxyPort(int)} or {@link #proxyScheme(String)} are specified,
197
+ * a proxy will not be used, and {@link LDClient} will connect to LaunchDarkly directly.
198
+ * </p>
199
+ * @param scheme
200
+ * @return
201
+ */
202
+ public Builder proxyScheme (String scheme ) {
203
+ this .proxyScheme = scheme ;
204
+ return this ;
205
+ }
206
+
207
+ HttpHost proxyHost () {
208
+ if (this .proxyHost == null && this .proxyPort == -1 && this .proxyScheme == null ) {
209
+ return null ;
210
+ } else {
211
+ String hostname = this .proxyHost == null ? "localhost" : this .proxyHost ;
212
+ String scheme = this .proxyScheme == null ? "https" : this .proxyScheme ;
213
+ return new HttpHost (hostname , this .proxyPort , scheme );
214
+ }
215
+ }
216
+
154
217
/**
155
218
* Build the configured {@link com.launchdarkly.client.LDConfig} object
156
219
* @return the {@link com.launchdarkly.client.LDConfig} configured by this builder
0 commit comments