Merged branch 'jetty-9.4.x' into 'jetty-10.0.x'.
This commit is contained in:
commit
6f211d7a34
|
@ -587,13 +587,14 @@ public class ForwardedRequestCustomizer implements Customizer
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void handleHost(HttpField field)
|
||||
{
|
||||
if (getForwardedPortAsAuthority() && !StringUtil.isEmpty(getForwardedPortHeader()))
|
||||
{
|
||||
if (_host == null)
|
||||
_host = new PossiblyPartialHostPort(getLeftMost(field.getValue()));
|
||||
else if (_for instanceof PortSetHostPort)
|
||||
else if (_host instanceof PortSetHostPort)
|
||||
_host = new HostPort(HostPort.normalizeHost(getLeftMost(field.getValue())), _host.getPort());
|
||||
}
|
||||
else if (_host == null)
|
||||
|
|
|
@ -397,6 +397,34 @@ public class ForwardedRequestCustomizerTest
|
|||
.requestURL("http://myhost:4444/")
|
||||
.remoteAddr("192.168.1.200").remotePort(0)
|
||||
),
|
||||
Arguments.of(new Request("X-Forwarded-* (all headers except server)")
|
||||
.headers(
|
||||
"GET / HTTP/1.1",
|
||||
"Host: myhost",
|
||||
"X-Forwarded-Proto: https",
|
||||
"X-Forwarded-Host: www.example.com",
|
||||
"X-Forwarded-Port: 4333",
|
||||
"X-Forwarded-For: 8.5.4.3:2222"
|
||||
),
|
||||
new Expectations()
|
||||
.scheme("https").serverName("www.example.com").serverPort(4333)
|
||||
.requestURL("https://www.example.com:4333/")
|
||||
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||
),
|
||||
Arguments.of(new Request("X-Forwarded-* (all headers except server, port first)")
|
||||
.headers(
|
||||
"GET / HTTP/1.1",
|
||||
"Host: myhost",
|
||||
"X-Forwarded-Proto: https",
|
||||
"X-Forwarded-Port: 4333",
|
||||
"X-Forwarded-Host: www.example.com",
|
||||
"X-Forwarded-For: 8.5.4.3:2222"
|
||||
),
|
||||
new Expectations()
|
||||
.scheme("https").serverName("www.example.com").serverPort(4333)
|
||||
.requestURL("https://www.example.com:4333/")
|
||||
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||
),
|
||||
Arguments.of(new Request("X-Forwarded-* (all headers)")
|
||||
.headers(
|
||||
"GET / HTTP/1.1",
|
||||
|
@ -427,6 +455,21 @@ public class ForwardedRequestCustomizerTest
|
|||
.requestURL("https://www.example.com:4333/")
|
||||
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||
),
|
||||
Arguments.of(new Request("X-Forwarded-* (all headers reversed)")
|
||||
.headers(
|
||||
"GET / HTTP/1.1",
|
||||
"Host: myhost",
|
||||
"X-Forwarded-Server: fw.example.com",
|
||||
"X-Forwarded-For: 8.5.4.3:2222",
|
||||
"X-Forwarded-Port: 4333",
|
||||
"X-Forwarded-Host: www.example.com",
|
||||
"X-Forwarded-Proto: https"
|
||||
),
|
||||
new Expectations()
|
||||
.scheme("https").serverName("www.example.com").serverPort(4333)
|
||||
.requestURL("https://www.example.com:4333/")
|
||||
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||
),
|
||||
Arguments.of(new Request("X-Forwarded-* (Server and Port)")
|
||||
.headers(
|
||||
"GET / HTTP/1.1",
|
||||
|
@ -440,6 +483,19 @@ public class ForwardedRequestCustomizerTest
|
|||
.requestURL("http://fw.example.com:4333/")
|
||||
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||
),
|
||||
Arguments.of(new Request("X-Forwarded-* (Port and Server)")
|
||||
.headers(
|
||||
"GET / HTTP/1.1",
|
||||
"Host: myhost",
|
||||
"X-Forwarded-Port: 4333",
|
||||
"X-Forwarded-For: 8.5.4.3:2222",
|
||||
"X-Forwarded-Server: fw.example.com"
|
||||
),
|
||||
new Expectations()
|
||||
.scheme("http").serverName("fw.example.com").serverPort(4333)
|
||||
.requestURL("http://fw.example.com:4333/")
|
||||
.remoteAddr("8.5.4.3").remotePort(2222)
|
||||
),
|
||||
|
||||
// =================================================================
|
||||
// Mixed Behavior
|
||||
|
|
|
@ -299,9 +299,6 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements TryExec
|
|||
|
||||
while (true)
|
||||
{
|
||||
if (!isRunning())
|
||||
return STOP;
|
||||
|
||||
try
|
||||
{
|
||||
Runnable task = _idleTime <= 0 ? _task.take() : _task.poll(_idleTime, _idleTimeUnit);
|
||||
|
@ -333,23 +330,26 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements TryExec
|
|||
{
|
||||
// test and increment size BEFORE decrementing pending,
|
||||
// so that we don't have a race starting new pending.
|
||||
while (true)
|
||||
int size = _size.get();
|
||||
|
||||
// Are we stopped?
|
||||
if (size < 0)
|
||||
return;
|
||||
|
||||
// Are we surplus to capacity?
|
||||
if (size >= _capacity)
|
||||
{
|
||||
int size = _size.get();
|
||||
if (size < 0)
|
||||
return;
|
||||
if (size >= _capacity)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("{} size {} > capacity", this, size, _capacity);
|
||||
if (_starting)
|
||||
_pending.decrementAndGet();
|
||||
return;
|
||||
}
|
||||
if (_size.compareAndSet(size, size + 1))
|
||||
break;
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("{} size {} > capacity", this, size, _capacity);
|
||||
if (_starting)
|
||||
_pending.decrementAndGet();
|
||||
return;
|
||||
}
|
||||
|
||||
// If we cannot update size then recalculate
|
||||
if (!_size.compareAndSet(size, size + 1))
|
||||
continue;
|
||||
|
||||
if (_starting)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
|
@ -362,7 +362,8 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements TryExec
|
|||
// that only effects the decision to keep other threads reserved.
|
||||
_stack.offerFirst(this);
|
||||
|
||||
// Wait for a task
|
||||
// Once added to the stack, we must always wait for a job on the _task Queue
|
||||
// and never return early, else we may leave a thread blocked offering a _task.
|
||||
Runnable task = reservedWait();
|
||||
|
||||
if (task == STOP)
|
||||
|
|
Loading…
Reference in New Issue