Issue #4645 - changes from review
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
d5ee7b058b
commit
633298b5c7
|
@ -36,8 +36,6 @@ import org.eclipse.jetty.util.ArrayTrie;
|
||||||
import org.eclipse.jetty.util.HostPort;
|
import org.eclipse.jetty.util.HostPort;
|
||||||
import org.eclipse.jetty.util.StringUtil;
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
import org.eclipse.jetty.util.Trie;
|
import org.eclipse.jetty.util.Trie;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
|
||||||
|
|
||||||
import static java.lang.invoke.MethodType.methodType;
|
import static java.lang.invoke.MethodType.methodType;
|
||||||
|
|
||||||
|
@ -64,8 +62,6 @@ import static java.lang.invoke.MethodType.methodType;
|
||||||
*/
|
*/
|
||||||
public class ForwardedRequestCustomizer implements Customizer
|
public class ForwardedRequestCustomizer implements Customizer
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(ForwardedRequestCustomizer.class);
|
|
||||||
|
|
||||||
private HostPortHttpField _forcedHost;
|
private HostPortHttpField _forcedHost;
|
||||||
private boolean _proxyAsAuthority = false;
|
private boolean _proxyAsAuthority = false;
|
||||||
private boolean _forwardedPortAsAuthority = true;
|
private boolean _forwardedPortAsAuthority = true;
|
||||||
|
@ -434,8 +430,7 @@ public class ForwardedRequestCustomizer implements Customizer
|
||||||
|
|
||||||
protected void onError(HttpField field, Throwable t)
|
protected void onError(HttpField field, Throwable t)
|
||||||
{
|
{
|
||||||
LOG.warn("Exception while processing {}", field, t);
|
throw new BadMessageException("Bad header value for " + field.getName(), t);
|
||||||
throw new BadMessageException("Bad header value for " + field.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getLeftMost(String headerValue)
|
protected String getLeftMost(String headerValue)
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.jetty.http.HttpTester;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
@ -619,6 +620,25 @@ public class ForwardedRequestCustomizerTest
|
||||||
expectations.accept(actual);
|
expectations.accept(actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBadInput() throws Exception
|
||||||
|
{
|
||||||
|
Request request = new Request("Bad port value")
|
||||||
|
.headers(
|
||||||
|
"GET / HTTP/1.1",
|
||||||
|
"Host: myhost",
|
||||||
|
"X-Forwarded-Port: "
|
||||||
|
);
|
||||||
|
|
||||||
|
request.configure(customizer);
|
||||||
|
|
||||||
|
String rawRequest = request.getRawRequest((header) -> header);
|
||||||
|
System.out.println(rawRequest);
|
||||||
|
|
||||||
|
HttpTester.Response response = HttpTester.parseResponse(connector.getResponse(rawRequest));
|
||||||
|
assertThat("status", response.getStatus(), is(400));
|
||||||
|
}
|
||||||
|
|
||||||
private static class Request
|
private static class Request
|
||||||
{
|
{
|
||||||
String description;
|
String description;
|
||||||
|
|
Loading…
Reference in New Issue