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

This commit is contained in:
Simone Bordet 2016-09-22 21:57:12 +02:00
commit 9551d0f62b
11 changed files with 180 additions and 142 deletions

View File

@ -459,9 +459,10 @@ public class HttpClient extends ContainerLifeCycle
HttpHeader.PROXY_AUTHORIZATION == header)
continue;
String name = field.getName();
String value = field.getValue();
if (!newRequest.getHeaders().contains(header, value))
newRequest.header(field.getName(), value);
if (!newRequest.getHeaders().contains(name, value))
newRequest.header(name, value);
}
return newRequest;
}

View File

@ -1549,6 +1549,68 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertThat(new String(response.getContent(), StandardCharsets.ISO_8859_1),Matchers.startsWith("[::1]:"));
}
@Test
public void testCopyRequest()
throws Exception
{
startClient();
assertCopyRequest(client.newRequest("http://example.com/some/url")
.method(HttpMethod.HEAD)
.version(HttpVersion.HTTP_2)
.content(new StringContentProvider("some string"))
.timeout(321, TimeUnit.SECONDS)
.idleTimeout(2221, TimeUnit.SECONDS)
.followRedirects(true)
.header(HttpHeader.CONTENT_TYPE, "application/json")
.header("X-Some-Custom-Header", "some-value"));
assertCopyRequest(client.newRequest("https://example.com")
.method(HttpMethod.POST)
.version(HttpVersion.HTTP_1_0)
.content(new StringContentProvider("some other string"))
.timeout(123231, TimeUnit.SECONDS)
.idleTimeout(232342, TimeUnit.SECONDS)
.followRedirects(false)
.header(HttpHeader.ACCEPT, "application/json")
.header("X-Some-Other-Custom-Header", "some-other-value"));
assertCopyRequest(client.newRequest("https://example.com")
.header(HttpHeader.ACCEPT, "application/json")
.header(HttpHeader.ACCEPT, "application/xml")
.header("x-same-name", "value1")
.header("x-same-name", "value2"));
assertCopyRequest(client.newRequest("https://example.com")
.header(HttpHeader.ACCEPT, "application/json")
.header(HttpHeader.CONTENT_TYPE, "application/json"));
assertCopyRequest(client.newRequest("https://example.com")
.header("Accept", "application/json")
.header("Content-Type", "application/json"));
assertCopyRequest(client.newRequest("https://example.com")
.header("X-Custom-Header-1", "value1")
.header("X-Custom-Header-2", "value2"));
assertCopyRequest(client.newRequest("https://example.com")
.header("X-Custom-Header-1", "value")
.header("X-Custom-Header-2", "value"));
}
private void assertCopyRequest(Request original)
{
Request copy = client.copyRequest((HttpRequest) original, original.getURI());
Assert.assertEquals(original.getURI(), copy.getURI());
Assert.assertEquals(original.getMethod(), copy.getMethod());
Assert.assertEquals(original.getVersion(), copy.getVersion());
Assert.assertEquals(original.getContent(), copy.getContent());
Assert.assertEquals(original.getIdleTimeout(), copy.getIdleTimeout());
Assert.assertEquals(original.getTimeout(), copy.getTimeout());
Assert.assertEquals(original.isFollowRedirects(), copy.isFollowRedirects());
Assert.assertEquals(original.getHeaders(), copy.getHeaders());
}
private void consume(InputStream input, boolean eof) throws IOException
{
int crlfs = 0;

View File

@ -65,5 +65,5 @@ Currently there are very few HTTP/2 configuration properties and the default val
|=======================================================================
|Property |Description
|jetty.http2.maxConcurrentStreams |The maximum number of concurrently open streams allowed on a single HTTP/2 connection (default 1024). Larger values increase parallelism but cost a memory commitment.
|jetty.http2.initialStreamSendWindow |The initial flow control window size for a new stream (default 65535). Larger values may allow greater throughput but also risk head of line blocking if TCP/IP flow control is triggered.
|jetty.http2.initialStreamRecvWindow |The initial receive flow control window size for a new stream (default 65535). Larger values may allow greater throughput but also risk head of line blocking if TCP/IP flow control is triggered.
|=======================================================================

View File

@ -10,7 +10,7 @@
<New class="org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory">
<Arg name="config"><Ref refid="sslHttpConfig"/></Arg>
<Set name="maxConcurrentStreams"><Property name="jetty.http2.maxConcurrentStreams" deprecated="http2.maxConcurrentStreams" default="1024"/></Set>
<Set name="initialStreamSendWindow"><Property name="jetty.http2.initialStreamSendWindow" default="65535"/></Set>
<Set name="initialStreamRecvWindow"><Property name="jetty.http2.initialStreamRecvWindow" default="65535"/></Set>
</New>
</Arg>
</Call>
@ -23,4 +23,3 @@
</Ref>
</Configure>

View File

@ -10,9 +10,8 @@
<New class="org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory">
<Arg name="config"><Ref refid="httpConfig"/></Arg>
<Set name="maxConcurrentStreams"><Property name="jetty.http2c.maxConcurrentStreams" deprecated="http2.maxConcurrentStreams" default="1024"/></Set>
<Set name="initialStreamSendWindow"><Property name="jetty.http2c.initialStreamSendWindow" default="65535"/></Set>
<Set name="initialStreamRecvWindow"><Property name="jetty.http2c.initialStreamRecvWindow" default="65535"/></Set>
</New>
</Arg>
</Call>
</Configure>

View File

@ -16,5 +16,5 @@ etc/jetty-http2.xml
## Max number of concurrent streams per connection
# jetty.http2.maxConcurrentStreams=1024
## Initial stream send (server to client) window
# jetty.http2.initialStreamSendWindow=65535
## Initial stream receive window (client to server)
# jetty.http2.initialStreamRecvWindow=65535

View File

@ -15,5 +15,5 @@ etc/jetty-http2c.xml
## Max number of concurrent streams per connection
# jetty.http2c.maxConcurrentStreams=1024
## Initial stream send (server to client) window
# jetty.http2c.initialStreamSendWindow=65535
## Initial stream receive window (client to server)
# jetty.http2c.initialStreamRecvWindow=65535

View File

@ -54,7 +54,6 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandler.Context;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.toolchain.test.http.SimpleHttpParser;
import org.eclipse.jetty.toolchain.test.http.SimpleHttpResponse;
import org.eclipse.jetty.util.IO;
@ -63,7 +62,6 @@ import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
@ -73,21 +71,19 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith (AdvancedRunner.class)
public class AsyncIOServletTest
{
private Server server;
private ServerConnector connector;
private LocalConnector local;
private ServletContextHandler context;
private String path = "/path";
private static final ThreadLocal<Throwable> scope = new ThreadLocal<>();
public void startServer(HttpServlet servlet) throws Exception
{
startServer(servlet,30000);
startServer(servlet, 30000);
}
public void startServer(HttpServlet servlet, long idleTimeout) throws Exception
{
server = new Server();
@ -98,7 +94,7 @@ public class AsyncIOServletTest
local = new LocalConnector(server);
server.addConnector(local);
context = new ServletContextHandler(server, "/", false, false);
ServletContextHandler context = new ServletContextHandler(server, "/", false, false);
ServletHolder holder = new ServletHolder(servlet);
holder.setAsyncSupported(true);
context.addServlet(holder, path);
@ -108,18 +104,19 @@ public class AsyncIOServletTest
@Override
public void enterScope(Context context, Request request, Object reason)
{
if (scope.get()!=null)
if (scope.get() != null)
{
System.err.println(Thread.currentThread()+" Already entered scope!!!");
System.err.println(Thread.currentThread() + " Already entered scope!!!");
scope.get().printStackTrace();
throw new IllegalStateException();
}
scope.set(new Throwable());
}
@Override
public void exitScope(Context context, Request request)
{
if (scope.get()==null)
if (scope.get() == null)
throw new IllegalStateException();
scope.set(null);
}
@ -130,7 +127,7 @@ public class AsyncIOServletTest
private static void assertScope()
{
if (scope.get()==null)
if (scope.get() == null)
Assert.fail("Not in scope");
}
@ -138,7 +135,7 @@ public class AsyncIOServletTest
public void stopServer() throws Exception
{
server.stop();
if (scope.get()!=null)
if (scope.get() != null)
{
System.err.println("Still in scope after stop!");
scope.get().printStackTrace();
@ -192,8 +189,8 @@ public class AsyncIOServletTest
public void onError(Throwable t)
{
assertScope();
Assert.assertThat("onError type",t,instanceOf(throwable.getClass()));
Assert.assertThat("onError message",t.getMessage(),is(throwable.getMessage()));
Assert.assertThat("onError type", t, instanceOf(throwable.getClass()));
Assert.assertThat("onError message", t.getMessage(), is(throwable.getMessage()));
latch.countDown();
response.setStatus(500);
@ -218,13 +215,13 @@ public class AsyncIOServletTest
output.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line=in.readLine();
String line = in.readLine();
assertThat(line, containsString("500 Server Error"));
while (line.length()>0)
while (line.length() > 0)
{
line=in.readLine();
line = in.readLine();
}
line=in.readLine();
line = in.readLine();
assertTrue(latch.await(5, TimeUnit.SECONDS));
}
@ -270,7 +267,7 @@ public class AsyncIOServletTest
}
});
}
},1000);
}, 1000);
String data1 = "0123456789";
String data2 = "ABCDEF";
@ -308,13 +305,13 @@ public class AsyncIOServletTest
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
assertScope();
if (request.getDispatcherType()==DispatcherType.ERROR)
if (request.getDispatcherType() == DispatcherType.ERROR)
{
response.flushBuffer();
return;
}
final AsyncContext asyncContext = request.startAsync(request, response);
request.startAsync(request, response);
request.getInputStream().setReadListener(new ReadListener()
{
@Override
@ -335,7 +332,10 @@ public class AsyncIOServletTest
{
assertScope();
errors.incrementAndGet();
throw new NullPointerException("explicitly_thrown_by_test_2"){{this.initCause(t);}};
throw new NullPointerException("explicitly_thrown_by_test_2")
{{
this.initCause(t);
}};
}
});
}
@ -435,8 +435,8 @@ public class AsyncIOServletTest
{
final CountDownLatch latch = new CountDownLatch(1);
String text = "Now is the winter of our discontent. How Now Brown Cow. The quick brown fox jumped over the lazy dog.\n";
for (int i=0;i<10;i++)
text=text+text;
for (int i = 0; i < 10; i++)
text = text + text;
final byte[] data = text.getBytes(StandardCharsets.ISO_8859_1);
startServer(new HttpServlet()
@ -462,11 +462,11 @@ public class AsyncIOServletTest
Thread.sleep(100);
out.write(data);
}
catch(IOException e)
catch (IOException e)
{
throw e;
}
catch(Exception e)
catch (Exception e)
{
e.printStackTrace();
}
@ -495,13 +495,13 @@ public class AsyncIOServletTest
output.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line=in.readLine();
String line = in.readLine();
assertThat(line, containsString("200 OK"));
while (line.length()>0)
line=in.readLine();
line=in.readLine();
while (line.length() > 0)
line = in.readLine();
line = in.readLine();
assertThat(line, not(containsString(" ")));
line=in.readLine();
line = in.readLine();
assertThat(line, containsString("discontent. How Now Brown Cow. The "));
}
@ -530,9 +530,9 @@ public class AsyncIOServletTest
in.setReadListener(new ReadListener()
{
transient int _i=0;
transient boolean _minusOne=false;;
transient boolean _finished=false;;
transient int _i = 0;
transient boolean _minusOne = false;
transient boolean _finished = false;
@Override
public void onError(Throwable t)
@ -546,24 +546,24 @@ public class AsyncIOServletTest
public void onDataAvailable() throws IOException
{
assertScope();
while(in.isReady() && !in.isFinished())
while (in.isReady() && !in.isFinished())
{
int b = in.read();
if (b==-1)
_minusOne=true;
else if (data[_i++]!=b)
if (b == -1)
_minusOne = true;
else if (data[_i++] != b)
throw new IllegalStateException();
}
if (in.isFinished())
_finished=true;
_finished = true;
}
@Override
public void onAllDataRead() throws IOException
{
assertScope();
out.write(String.format("i=%d eof=%b finished=%b",_i,_minusOne,_finished).getBytes(StandardCharsets.ISO_8859_1));
out.write(String.format("i=%d eof=%b finished=%b", _i, _minusOne, _finished).getBytes(StandardCharsets.ISO_8859_1));
async.complete();
}
});
@ -572,8 +572,8 @@ public class AsyncIOServletTest
String request = "GET " + path + " HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Content-Type: text/plain\r\n"+
"Content-Length: "+data.length+"\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Length: " + data.length + "\r\n" +
"Connection: close\r\n" +
"\r\n";
@ -586,12 +586,12 @@ public class AsyncIOServletTest
output.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line=in.readLine();
String line = in.readLine();
assertThat(line, containsString("200 OK"));
while (line.length()>0)
line=in.readLine();
line=in.readLine();
assertThat(line, containsString("i="+data.length+" eof=true finished=true"));
while (line.length() > 0)
line = in.readLine();
line = in.readLine();
assertThat(line, containsString("i=" + data.length + " eof=true finished=true"));
}
}
@ -634,14 +634,14 @@ public class AsyncIOServletTest
Thread.sleep(1000);
if (!in.isReady())
throw new IllegalStateException();
if (in.read()!='X')
if (in.read() != 'X')
throw new IllegalStateException();
if (!in.isReady())
throw new IllegalStateException();
if (in.read()!=-1)
if (in.read() != -1)
throw new IllegalStateException();
}
catch(Exception e)
catch (Exception e)
{
e.printStackTrace();
}
@ -660,8 +660,8 @@ public class AsyncIOServletTest
String request = "GET " + path + " HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Content-Type: text/plain\r\n"+
"Content-Length: "+data.length+"\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Length: " + data.length + "\r\n" +
"Connection: close\r\n" +
"\r\n";
@ -676,11 +676,11 @@ public class AsyncIOServletTest
output.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line=in.readLine();
String line = in.readLine();
assertThat(line, containsString("200 OK"));
while (line.length()>0)
line=in.readLine();
line=in.readLine();
while (line.length() > 0)
line = in.readLine();
line = in.readLine();
assertThat(line, containsString("OK"));
}
}
@ -704,7 +704,7 @@ public class AsyncIOServletTest
final ServletInputStream in = request.getInputStream();
final ServletOutputStream out = response.getOutputStream();
if (request.getDispatcherType()==DispatcherType.ERROR)
if (request.getDispatcherType() == DispatcherType.ERROR)
throw new IllegalStateException();
in.setReadListener(new ReadListener()
@ -721,28 +721,24 @@ public class AsyncIOServletTest
public void onDataAvailable() throws IOException
{
assertScope();
async.start(
new Runnable()
async.start(() ->
{
public void run()
assertScope();
try
{
assertScope();
try
{
Thread.sleep(1000);
if (!in.isReady())
throw new IllegalStateException();
if (in.read()!='X')
throw new IllegalStateException();
if (!in.isReady())
throw new IllegalStateException();
if (in.read()!=-1)
throw new IllegalStateException();
}
catch(Exception e)
{
e.printStackTrace();
}
Thread.sleep(1000);
if (!in.isReady())
throw new IllegalStateException();
if (in.read() != 'X')
throw new IllegalStateException();
if (!in.isReady())
throw new IllegalStateException();
if (in.read() != -1)
throw new IllegalStateException();
}
catch (Exception e)
{
e.printStackTrace();
}
});
}
@ -759,8 +755,8 @@ public class AsyncIOServletTest
String request = "GET " + path + " HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Content-Type: text/plain\r\n"+
"Content-Length: "+data.length+"\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Length: " + data.length + "\r\n" +
"Connection: close\r\n" +
"\r\n";
@ -775,11 +771,11 @@ public class AsyncIOServletTest
output.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line=in.readLine();
String line = in.readLine();
assertThat(line, containsString("200 OK"));
while (line.length()>0)
line=in.readLine();
line=in.readLine();
while (line.length() > 0)
line = in.readLine();
line = in.readLine();
assertThat(line, containsString("OK"));
}
}
@ -820,7 +816,7 @@ public class AsyncIOServletTest
while (in.isReady())
{
int b = in.read();
if (b<0)
if (b < 0)
{
out.write("OK\n".getBytes(StandardCharsets.ISO_8859_1));
async.complete();
@ -843,8 +839,8 @@ public class AsyncIOServletTest
String request = "GET " + path + " HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Content-Type: text/plain\r\n"+
"Content-Length: "+data.length+"\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Length: " + data.length + "\r\n" +
"Connection: close\r\n" +
"\r\n";
@ -858,13 +854,13 @@ public class AsyncIOServletTest
output.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line=in.readLine();
String line = in.readLine();
assertThat(line, containsString("200 OK"));
while (line.length()>0)
while (line.length() > 0)
{
line=in.readLine();
line = in.readLine();
}
line=in.readLine();
line = in.readLine();
assertThat(line, containsString("OK"));
Assert.assertFalse(allDataRead.get());
}
@ -926,7 +922,7 @@ public class AsyncIOServletTest
output.flush();
String response = IO.toString(client.getInputStream());
assertThat(response,containsString(" 200 OK"));
assertThat(response, containsString(" 200 OK"));
// wait for onAllDataRead BEFORE closing client
latch.await();
}
@ -990,7 +986,7 @@ public class AsyncIOServletTest
@Override
public void onWritePossible() throws IOException
{
if (writeLatch.getCount()==0)
if (writeLatch.getCount() == 0)
asyncContext.complete();
else
writeLatch.countDown();
@ -1013,7 +1009,7 @@ public class AsyncIOServletTest
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n" +
Integer.toHexString(content.length())+"\r\n" +
Integer.toHexString(content.length()) + "\r\n" +
content + "\r\n";
endp.addInput(ByteBuffer.wrap(request.getBytes("UTF-8")));

View File

@ -10,7 +10,7 @@
<New class="org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory">
<Arg name="config"><Ref refid="unixSocketHttpConfig"/></Arg>
<Set name="maxConcurrentStreams"><Property name="jetty.http2c.maxConcurrentStreams" default="1024"/></Set>
<Set name="initialStreamSendWindow"><Property name="jetty.http2c.initialStreamSendWindow" default="65535"/></Set>
<Set name="initialStreamRecvWindow"><Property name="jetty.http2c.initialStreamRecvWindow" default="65535"/></Set>
</New>
</Arg>
</Call>

View File

@ -16,6 +16,5 @@ etc/jetty-unixsocket-http2c.xml
## Max number of concurrent streams per connection
# jetty.http2.maxConcurrentStreams=1024
## Initial stream send (server to client) window
# jetty.http2.initialStreamSendWindow=65535
## Initial stream receive window (client to server)
# jetty.http2.initialStreamRecvWindow=65535

View File

@ -27,8 +27,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Ignore;
@ -51,21 +49,17 @@ public class HttpClientConnectTimeoutTest extends AbstractTest
int connectTimeout = 1000;
assumeConnectTimeout(host, port, connectTimeout);
start(null);
start(new EmptyServerHandler());
client.stop();
client.setConnectTimeout(connectTimeout);
client.start();
final CountDownLatch latch = new CountDownLatch(1);
Request request = client.newRequest(host, port);
request.send(new Response.CompleteListener()
request.send(result ->
{
@Override
public void onComplete(Result result)
{
if (result.isFailed())
latch.countDown();
}
if (result.isFailed())
latch.countDown();
});
Assert.assertTrue(latch.await(2 * connectTimeout, TimeUnit.MILLISECONDS));
@ -80,7 +74,7 @@ public class HttpClientConnectTimeoutTest extends AbstractTest
int connectTimeout = 2000;
assumeConnectTimeout(host, port, connectTimeout);
start(null);
start(new EmptyServerHandler());
client.stop();
client.setConnectTimeout(connectTimeout);
client.start();
@ -89,14 +83,10 @@ public class HttpClientConnectTimeoutTest extends AbstractTest
final CountDownLatch latch = new CountDownLatch(2);
Request request = client.newRequest(host, port);
request.timeout(connectTimeout / 2, TimeUnit.MILLISECONDS)
.send(new Response.CompleteListener()
.send(result ->
{
@Override
public void onComplete(Result result)
{
completes.incrementAndGet();
latch.countDown();
}
completes.incrementAndGet();
latch.countDown();
});
Assert.assertFalse(latch.await(2 * connectTimeout, TimeUnit.MILLISECONDS));
@ -112,31 +102,23 @@ public class HttpClientConnectTimeoutTest extends AbstractTest
int connectTimeout = 1000;
assumeConnectTimeout(host, port, connectTimeout);
start(null);
start(new EmptyServerHandler());
client.stop();
client.setConnectTimeout(connectTimeout);
client.start();
final CountDownLatch latch = new CountDownLatch(1);
Request request = client.newRequest(host, port);
request.send(new Response.CompleteListener()
request.send(result1 ->
{
@Override
public void onComplete(Result result)
if (result1.isFailed())
{
if (result.isFailed())
// Retry
client.newRequest(host, port).send(result2 ->
{
// Retry
client.newRequest(host, port).send(new Response.CompleteListener()
{
@Override
public void onComplete(Result result)
{
if (result.isFailed())
latch.countDown();
}
});
}
if (result2.isFailed())
latch.countDown();
});
}
});