Skip to content

Add support for native http proxying. #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public OptimizelyHttpClient build() {
.setDefaultRequestConfig(HttpClientUtils.DEFAULT_REQUEST_CONFIG)
.setConnectionManager(poolingHttpClientConnectionManager)
.disableCookieManagement()
.useSystemProperties()
.build();

return new OptimizelyHttpClient(closableHttpClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
*/
package com.optimizely.ab;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.CloseableHttpClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
Expand All @@ -33,6 +34,16 @@

public class OptimizelyHttpClientTest {

@Before
public void setUp() {
System.setProperty("https.proxyHost", "localhost");
}

@After
public void tearDown() {
System.clearProperty("https.proxyHost");
}

@Test
public void testDefaultConfiguration() {
OptimizelyHttpClient optimizelyHttpClient = OptimizelyHttpClient.builder().build();
Expand All @@ -50,6 +61,15 @@ public void testNonDefaultConfiguration() {
assertTrue(optimizelyHttpClient.getHttpClient() instanceof CloseableHttpClient);
}

@Test(expected = HttpHostConnectException.class)
public void testProxySettings() throws IOException {
OptimizelyHttpClient optimizelyHttpClient = OptimizelyHttpClient.builder().build();

// If this request succeeds then the proxy config was not picked up.
HttpGet get = new HttpGet("https://www.optimizely.com");
optimizelyHttpClient.execute(get);
}

@Test
public void testExecute() throws IOException {
HttpUriRequest httpUriRequest = RequestBuilder.get().build();
Expand Down
2 changes: 2 additions & 0 deletions java-quickstart/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ dependencies {
}

task runExample(type: JavaExec) {
systemProperties System.properties

main "com.optimizely.Example"
classpath sourceSets.test.runtimeClasspath
}