-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for X-Forwarded-Host in reverse proxy scenarios
- Loading branch information
1 parent
c0fc998
commit d7207f7
Showing
3 changed files
with
41 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.googlecode.utterlyidle; | ||
|
||
import org.junit.Test; | ||
|
||
import static com.googlecode.totallylazy.Assert.assertThat; | ||
import static com.googlecode.totallylazy.predicates.Predicates.is; | ||
import static com.googlecode.utterlyidle.BasePath.basePath; | ||
import static com.googlecode.utterlyidle.BaseUri.baseUri; | ||
import static com.googlecode.utterlyidle.HttpHeaders.HOST; | ||
import static com.googlecode.utterlyidle.HttpHeaders.X_FORWARDED_HOST; | ||
import static com.googlecode.utterlyidle.HttpHeaders.X_FORWARDED_PROTO; | ||
import static com.googlecode.utterlyidle.Request.get; | ||
|
||
public class BaseUriTest { | ||
@Test | ||
public void whenNoHostDefaultToBasePath() throws Exception { | ||
assertThat(baseUri(get("foo"), basePath("/root/")), is(baseUri("/root/"))); | ||
} | ||
|
||
@Test | ||
public void whenHostIsSetUseThat() throws Exception { | ||
assertThat(baseUri(get("foo").header(HOST, "server"), basePath("/root/")), is(baseUri("http://server/root/"))); | ||
} | ||
|
||
@Test | ||
public void whenXForwardedHostIsSetUseThatOverHost() throws Exception { | ||
assertThat(baseUri(get("foo").header(HOST, "internal").header(X_FORWARDED_HOST, "external"), basePath("/root/")), is(baseUri("http://external/root/"))); | ||
} | ||
|
||
@Test | ||
public void whenXForwardedProtoIsSetUseThatOverDefaultHttp() throws Exception { | ||
assertThat(baseUri(get("foo").header(HOST, "server").header(X_FORWARDED_PROTO, "https"), basePath("/root/")), is(baseUri("https://server/root/"))); | ||
} | ||
} |