Issue #4645 - handle exceptions from all headers
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
dbd89ce1c7
commit
d5ee7b058b
|
@ -36,6 +36,8 @@ import org.eclipse.jetty.util.ArrayTrie;
|
|||
import org.eclipse.jetty.util.HostPort;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
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;
|
||||
|
||||
|
@ -62,6 +64,8 @@ import static java.lang.invoke.MethodType.methodType;
|
|||
*/
|
||||
public class ForwardedRequestCustomizer implements Customizer
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ForwardedRequestCustomizer.class);
|
||||
|
||||
private HostPortHttpField _forcedHost;
|
||||
private boolean _proxyAsAuthority = false;
|
||||
private boolean _forwardedPortAsAuthority = true;
|
||||
|
@ -380,11 +384,18 @@ public class ForwardedRequestCustomizer implements Customizer
|
|||
try
|
||||
{
|
||||
for (HttpField field : httpFields)
|
||||
{
|
||||
try
|
||||
{
|
||||
MethodHandle handle = _handles.get(field.getName());
|
||||
if (handle != null)
|
||||
handle.invoke(forwarded, field);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
onError(field, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
|
@ -421,6 +432,12 @@ public class ForwardedRequestCustomizer implements Customizer
|
|||
}
|
||||
}
|
||||
|
||||
protected void onError(HttpField field, Throwable t)
|
||||
{
|
||||
LOG.warn("Exception while processing {}", field, t);
|
||||
throw new BadMessageException("Bad header value for " + field.getName());
|
||||
}
|
||||
|
||||
protected String getLeftMost(String headerValue)
|
||||
{
|
||||
if (headerValue == null)
|
||||
|
@ -592,8 +609,6 @@ public class ForwardedRequestCustomizer implements Customizer
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
public void handleHost(HttpField field)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (getForwardedPortAsAuthority() && !StringUtil.isEmpty(getForwardedPortHeader()))
|
||||
{
|
||||
|
@ -607,11 +622,6 @@ public class ForwardedRequestCustomizer implements Customizer
|
|||
_host = new HostPort(getLeftMost(field.getValue()));
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
throw new BadMessageException("Bad header value for " + field.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void handleServer(HttpField field)
|
||||
|
@ -630,8 +640,6 @@ public class ForwardedRequestCustomizer implements Customizer
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
public void handleFor(HttpField field)
|
||||
{
|
||||
try
|
||||
{
|
||||
String authority = getLeftMost(field.getValue());
|
||||
if (!getForwardedPortAsAuthority() && !StringUtil.isEmpty(getForwardedPortHeader()))
|
||||
|
@ -646,16 +654,9 @@ public class ForwardedRequestCustomizer implements Customizer
|
|||
_for = new HostPort(authority);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
throw new BadMessageException("Bad header value for " + field.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void handlePort(HttpField field)
|
||||
{
|
||||
try
|
||||
{
|
||||
int port = HostPort.parsePort(getLeftMost(field.getValue()));
|
||||
if (!getForwardedPortAsAuthority())
|
||||
|
@ -673,11 +674,6 @@ public class ForwardedRequestCustomizer implements Customizer
|
|||
_host = new HostPort(HostPort.normalizeHost(_host.getHost()), port);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
throw new BadMessageException("Bad header value for " + field.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void handleHttps(HttpField field)
|
||||
|
|
Loading…
Reference in New Issue