Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit b8d9afb

Browse files
authored
Merge pull request #85 from launchdarkly/arun/proxy-config
Propagate proxy configuration to okhttp client
2 parents ff5ee95 + 79621dc commit b8d9afb

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repositories {
1919

2020
allprojects {
2121
group = 'com.launchdarkly'
22-
version = "2.0.8"
22+
version = "2.0.9-SNAPSHOT"
2323
sourceCompatibility = 1.7
2424
targetCompatibility = 1.7
2525
}
@@ -32,7 +32,7 @@ dependencies {
3232
compile "com.google.guava:guava:19.0"
3333
compile "joda-time:joda-time:2.9.3"
3434
compile "org.slf4j:slf4j-api:1.7.21"
35-
compile group: "com.launchdarkly", name: "okhttp-eventsource", version: "1.0.0", changing: true
35+
compile group: "com.launchdarkly", name: "okhttp-eventsource", version: "1.1.0", changing: true
3636
compile "redis.clients:jedis:2.9.0"
3737
testCompile "org.easymock:easymock:3.4"
3838
testCompile 'junit:junit:4.12'

src/main/java/com/launchdarkly/client/StreamProcessor.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.launchdarkly.eventsource.MessageEvent;
88
import com.launchdarkly.eventsource.ReadyState;
99
import okhttp3.Headers;
10+
11+
import org.apache.http.HttpHost;
1012
import org.joda.time.DateTime;
1113
import org.slf4j.Logger;
1214
import org.slf4j.LoggerFactory;
@@ -124,11 +126,24 @@ public void onError(Throwable throwable) {
124126
}
125127
};
126128

127-
es = new EventSource.Builder(handler, URI.create(config.streamURI.toASCIIString() + "/flags"))
129+
EventSource.Builder builder = new EventSource.Builder(handler, URI.create(config.streamURI.toASCIIString() + "/flags"))
128130
.headers(headers)
129-
.reconnectTimeMs(config.reconnectTimeMs)
130-
.build();
131+
.reconnectTimeMs(config.reconnectTimeMs);
132+
if (config.proxyHost != null) {
133+
int proxyPort = config.proxyHost.getPort();
134+
if (proxyPort == -1) {
135+
String scheme = config.proxyHost.getSchemeName();
136+
if (scheme == "http")
137+
proxyPort = 80;
138+
else if (scheme == "https")
139+
proxyPort = 443;
140+
else
141+
logger.error("Unknown proxy scheme: " + scheme);
142+
}
143+
builder.proxy(config.proxyHost.getHostName(), proxyPort);
144+
}
131145

146+
es = builder.build();
132147
es.start();
133148
return initFuture;
134149
}

0 commit comments

Comments
 (0)