11package com .launchdarkly .client ;
22
3+ import org .apache .http .HttpHost ;
34import org .apache .http .client .methods .HttpGet ;
45import org .apache .http .client .methods .HttpPost ;
56import org .apache .http .client .utils .URIBuilder ;
@@ -27,13 +28,15 @@ public final class LDConfig {
2728 final int connectTimeout ;
2829 final int socketTimeout ;
2930 final int flushInterval ;
31+ final HttpHost proxyHost ;
3032
3133 protected LDConfig (Builder builder ) {
3234 this .baseURI = builder .baseURI ;
3335 this .capacity = builder .capacity ;
3436 this .connectTimeout = builder .connectTimeout ;
3537 this .socketTimeout = builder .socketTimeout ;
3638 this .flushInterval = builder .flushInterval ;
39+ this .proxyHost = builder .proxyHost ();
3740 }
3841
3942 /**
@@ -54,6 +57,9 @@ public static class Builder{
5457 private int socketTimeout = DEFAULT_SOCKET_TIMEOUT ;
5558 private int capacity = DEFAULT_CAPACITY ;
5659 private int flushInterval = DEFAULT_FLUSH_INTERVAL ;
60+ private String proxyHost ;
61+ private int proxyPort = -1 ;
62+ private String proxyScheme ;
5763
5864 /**
5965 * Creates a builder with all configuration parameters set to the default
@@ -151,6 +157,63 @@ public Builder capacity(int capacity) {
151157 return this ;
152158 }
153159
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+
154217 /**
155218 * Build the configured {@link com.launchdarkly.client.LDConfig} object
156219 * @return the {@link com.launchdarkly.client.LDConfig} configured by this builder
0 commit comments