Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jetty-12.0.x' into jetty-12.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw committed Sep 24, 2024
2 parents 3b1f38e + 1d9f108 commit 7367bce
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class Server extends Handler.Wrapper implements Attributes
private final AutoLock _dateLock = new AutoLock();
private final MimeTypes.Mutable _mimeTypes = new MimeTypes.Mutable();
private String _serverInfo = __serverInfo;
private boolean _openEarly = true;
private boolean _stopAtShutdown;
private boolean _dumpAfterStart;
private boolean _dumpBeforeStop;
Expand Down Expand Up @@ -276,6 +277,22 @@ public InvocationType getInvocationType()
return type;
}

public boolean isOpenEarly()
{
return _openEarly;
}

/**
* Allows to disable early opening of network sockets. Network sockets are opened early by default.
* @param openEarly If {@code openEarly} is {@code true} (default), network sockets are opened before
* starting other components. If {@code openEarly} is {@code false}, network connectors open sockets
* when they're started.
*/
public void setOpenEarly(boolean openEarly)
{
_openEarly = openEarly;
}

public boolean isDryRun()
{
return _dryRun;
Expand Down Expand Up @@ -543,7 +560,7 @@ protected void doStart() throws Exception
final ExceptionUtil.MultiException multiException = new ExceptionUtil.MultiException();

// Open network connector to ensure ports are available
if (!_dryRun)
if (!_dryRun && _openEarly)
{
_connectors.stream().filter(NetworkConnector.class::isInstance).map(NetworkConnector.class::cast).forEach(connector ->
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.eclipse.jetty.client.HttpProxy;
import org.eclipse.jetty.client.Request;
import org.eclipse.jetty.client.Response;
import org.eclipse.jetty.client.StringRequestContent;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.http.HttpHeader;
Expand All @@ -79,6 +80,7 @@
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.util.ajax.JSON;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -163,11 +165,32 @@ private void startClient() throws Exception
}

@AfterEach
public void dispose() throws Exception
public void dispose()
{
client.stop();
proxy.stop();
server.stop();
LifeCycle.stop(client);
LifeCycle.stop(proxy);
LifeCycle.stop(server);
}

@Test
public void testExpect100WithBody() throws Exception
{
startServer(new EchoHttpServlet());
startProxy(new AsyncMiddleManServlet());
startClient();

for (int i = 0; i < 100; i++)
{
String body = Character.toString('a' + (i % 26)); // only use 'a' to 'z'
ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort())
.path("/" + body)
.headers(h -> h.put(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE))
.timeout(5, TimeUnit.SECONDS)
.body(new StringRequestContent(body))
.send();
assertEquals(200, response.getStatus());
assertEquals(body, response.getContentAsString());
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.eclipse.jetty.client.HttpProxy;
import org.eclipse.jetty.client.Request;
import org.eclipse.jetty.client.Response;
import org.eclipse.jetty.client.StringRequestContent;
import org.eclipse.jetty.ee9.servlet.ServletContextHandler;
import org.eclipse.jetty.ee9.servlet.ServletHolder;
import org.eclipse.jetty.http.HttpHeader;
Expand Down Expand Up @@ -163,11 +164,32 @@ private void startClient() throws Exception
}

@AfterEach
public void dispose() throws Exception
public void dispose()
{
LifeCycle.stop(client);
LifeCycle.stop(proxy);
LifeCycle.stop(proxy);
LifeCycle.stop(server);
}

@Test
public void testExpect100WithBody() throws Exception
{
startServer(new EchoHttpServlet());
startProxy(new AsyncMiddleManServlet());
startClient();

for (int i = 0; i < 100; i++)
{
String body = Character.toString('a' + (i % 26)); // only use 'a' to 'z'
ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort())
.path("/" + body)
.headers(h -> h.put(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE))
.timeout(5, TimeUnit.SECONDS)
.body(new StringRequestContent(body))
.send();
assertEquals(200, response.getStatus());
assertEquals(body, response.getContentAsString());
}
}

@Test
Expand Down

0 comments on commit 7367bce

Please sign in to comment.