Merged branch 'jetty-9.4.x' into 'jetty-10.0.x'.

This commit is contained in:
Simone Bordet 2020-02-16 17:29:10 +01:00
commit 6f211d7a34
3 changed files with 77 additions and 19 deletions

View File

@ -587,13 +587,14 @@ public class ForwardedRequestCustomizer implements Customizer
} }
} }
@SuppressWarnings("unused")
public void handleHost(HttpField field) public void handleHost(HttpField field)
{ {
if (getForwardedPortAsAuthority() && !StringUtil.isEmpty(getForwardedPortHeader())) if (getForwardedPortAsAuthority() && !StringUtil.isEmpty(getForwardedPortHeader()))
{ {
if (_host == null) if (_host == null)
_host = new PossiblyPartialHostPort(getLeftMost(field.getValue())); _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()); _host = new HostPort(HostPort.normalizeHost(getLeftMost(field.getValue())), _host.getPort());
} }
else if (_host == null) else if (_host == null)

View File

@ -397,6 +397,34 @@ public class ForwardedRequestCustomizerTest
.requestURL("http://myhost:4444/") .requestURL("http://myhost:4444/")
.remoteAddr("192.168.1.200").remotePort(0) .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)") Arguments.of(new Request("X-Forwarded-* (all headers)")
.headers( .headers(
"GET / HTTP/1.1", "GET / HTTP/1.1",
@ -427,6 +455,21 @@ public class ForwardedRequestCustomizerTest
.requestURL("https://www.example.com:4333/") .requestURL("https://www.example.com:4333/")
.remoteAddr("8.5.4.3").remotePort(2222) .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)") Arguments.of(new Request("X-Forwarded-* (Server and Port)")
.headers( .headers(
"GET / HTTP/1.1", "GET / HTTP/1.1",
@ -440,6 +483,19 @@ public class ForwardedRequestCustomizerTest
.requestURL("http://fw.example.com:4333/") .requestURL("http://fw.example.com:4333/")
.remoteAddr("8.5.4.3").remotePort(2222) .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 // Mixed Behavior

View File

@ -299,9 +299,6 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements TryExec
while (true) while (true)
{ {
if (!isRunning())
return STOP;
try try
{ {
Runnable task = _idleTime <= 0 ? _task.take() : _task.poll(_idleTime, _idleTimeUnit); 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, // test and increment size BEFORE decrementing pending,
// so that we don't have a race starting new 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 (LOG.isDebugEnabled())
if (size < 0) LOG.debug("{} size {} > capacity", this, size, _capacity);
return; if (_starting)
if (size >= _capacity) _pending.decrementAndGet();
{ return;
if (LOG.isDebugEnabled())
LOG.debug("{} size {} > capacity", this, size, _capacity);
if (_starting)
_pending.decrementAndGet();
return;
}
if (_size.compareAndSet(size, size + 1))
break;
} }
// If we cannot update size then recalculate
if (!_size.compareAndSet(size, size + 1))
continue;
if (_starting) if (_starting)
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -362,7 +362,8 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements TryExec
// that only effects the decision to keep other threads reserved. // that only effects the decision to keep other threads reserved.
_stack.offerFirst(this); _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(); Runnable task = reservedWait();
if (task == STOP) if (task == STOP)