Skip to content

Commit

Permalink
fix #126 Correctly use base hostname in HttpClientOptions even if proxy
Browse files Browse the repository at this point in the history
This commit fixes the HttpClientOptions to correctly derive relative
urls from the base url, even when a proxy is configured. It would
previously wrongly replace the hostname with `localhost`.
  • Loading branch information
simonbasle committed Jul 6, 2017
1 parent 59472c6 commit 32ed1f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ final String formatSchemeAndHost(String url, boolean ws) {
if (url.startsWith("/")) {
SocketAddress remote = getAddress();

if (remote != null && !useProxy() && remote instanceof InetSocketAddress) {
if (remote != null && remote instanceof InetSocketAddress) {
InetSocketAddress inet = (InetSocketAddress) remote;

return scheme + inet.getHostName() + ":" + inet.getPort() + url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ public void formatSchemeAndHostRelativeAddressSsl() throws Exception {
assertThat(test2).isEqualTo("wss://example:8080/foo");
}

@Test
public void formatSchemeAndHostRelativeAndProxy() {
String test = this.builder.proxyOptions(proxyOptions)
.host("google.com")
.port(80)
.build()
.formatSchemeAndHost("/foo", false);

assertThat(test).isEqualTo("http://google.com:80/foo");
}

@Test
public void formatSchemeAndHostAbsoluteHttp() throws Exception {
String test1 = this.builder.build()
Expand Down

0 comments on commit 32ed1f5

Please sign in to comment.