Issue #4048 Multiple proxy ports (#4063)

Support multiple proxy port values.

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-09-06 14:45:00 +10:00 committed by GitHub
parent 74e560fb7a
commit 894f31e612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -630,16 +630,16 @@ public class ForwardedRequestCustomizer implements Customizer
if (!getForwardedPortAsAuthority()) if (!getForwardedPortAsAuthority())
{ {
if (_for == null) if (_for == null)
_for = new PortSetHostPort(_request.getRemoteHost(), field.getIntValue()); _for = new PortSetHostPort(_request.getRemoteHost(), Integer.parseInt(getLeftMost(field.getValue())));
else if (_for instanceof PossiblyPartialHostPort && _for.getPort() <= 0) else if (_for instanceof PossiblyPartialHostPort && _for.getPort() <= 0)
_for = new HostPort(HostPort.normalizeHost(_for.getHost()), field.getIntValue()); _for = new HostPort(HostPort.normalizeHost(_for.getHost()), Integer.parseInt(getLeftMost(field.getValue())));
} }
else else
{ {
if (_host == null) if (_host == null)
_host = new PortSetHostPort(_request.getServerName(), field.getIntValue()); _host = new PortSetHostPort(_request.getServerName(), Integer.parseInt(getLeftMost(field.getValue())));
else if (_host instanceof PossiblyPartialHostPort && _host.getPort() <= 0) else if (_host instanceof PossiblyPartialHostPort && _host.getPort() <= 0)
_host = new HostPort(HostPort.normalizeHost(_host.getHost()), field.getIntValue()); _host = new HostPort(HostPort.normalizeHost(_host.getHost()), Integer.parseInt(getLeftMost(field.getValue())));
} }
} }

View File

@ -348,6 +348,18 @@ public class ForwardedRequestCustomizerTest
.requestURL("http://myhost:2222/") .requestURL("http://myhost:2222/")
.remoteAddr("[1:2:3:4:5:6:7:8]").remotePort(0) .remoteAddr("[1:2:3:4:5:6:7:8]").remotePort(0)
), ),
Arguments.of(new Request("X-Forwarded-For and X-Forwarded-Port (multiple times combined)")
.headers(
"GET / HTTP/1.1",
"Host: myhost",
"X-Forwarded-Port: 2222, 3333",
"X-Forwarded-For: 1:2:3:4:5:6:7:8, 7:7:7:7:7:7:7:7"
),
new Expectations()
.scheme("http").serverName("myhost").serverPort(2222)
.requestURL("http://myhost:2222/")
.remoteAddr("[1:2:3:4:5:6:7:8]").remotePort(0)
),
Arguments.of(new Request("X-Forwarded-Port") Arguments.of(new Request("X-Forwarded-Port")
.headers( .headers(
"GET / HTTP/1.1", "GET / HTTP/1.1",