Skip to content

Commit ebc5e55

Browse files
authored
Removed reliance on exception to shutdown non persistent connections (#12213)
Moved the shutdownOutput in HttpStreamOverHttp1 to before the continuation of handling
1 parent 1726c87 commit ebc5e55

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,11 @@ public void onFillable()
371371
{
372372
while (getEndPoint().isOpen())
373373
{
374-
if (LOG.isDebugEnabled())
375-
LOG.debug("onFillable fill and parse {} {} {}", this, _httpChannel, _retainableByteBuffer);
376-
377374
// Fill the request buffer (if needed).
378375
int filled = fillRequestBuffer();
376+
if (LOG.isDebugEnabled())
377+
LOG.debug("onFillable filled {} {} {} {}", filled, this, _httpChannel, _retainableByteBuffer);
378+
379379
if (filled < 0 && getEndPoint().isOutputShutdown())
380380
close();
381381

@@ -1523,12 +1523,17 @@ public void succeeded()
15231523
return;
15241524
}
15251525

1526+
// As this is not an upgrade, we can shutdown the output if we know we are not persistent
1527+
if (_sendCallback._shutdownOut)
1528+
getEndPoint().shutdownOutput();
1529+
15261530
_httpChannel.recycle();
15271531

1532+
1533+
// If a 100 Continue is still expected to be sent, but no content was read, then
1534+
// close the parser so that seeks EOF below, not the next request.
15281535
if (_expects100Continue)
15291536
{
1530-
// No content was read, and no 100 Continue response was sent.
1531-
// Close the parser so that below it seeks EOF, not the next request.
15321537
_expects100Continue = false;
15331538
_parser.close();
15341539
}
@@ -1541,7 +1546,6 @@ public void succeeded()
15411546
else
15421547
_parser.close();
15431548
}
1544-
15451549
_generator.reset();
15461550

15471551
// Can the onFillable thread continue processing
@@ -1552,9 +1556,6 @@ public void succeeded()
15521556
if (LOG.isDebugEnabled())
15531557
LOG.debug("non-current completion {}", this);
15541558

1555-
if (_sendCallback._shutdownOut)
1556-
getEndPoint().shutdownOutput();
1557-
15581559
// If we are looking for the next request
15591560
if (_parser.isStart())
15601561
{

jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public boolean handle(Request request, Response response, Callback callback)
200200
}
201201
});
202202

203-
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
203+
try (StacklessLogging ignored = new StacklessLogging(Response.class); Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
204204
{
205205
OutputStream os = client.getOutputStream();
206206

@@ -233,7 +233,7 @@ public boolean handle(Request request, Response response, Callback callback) thr
233233
}
234234
});
235235

236-
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
236+
try (StacklessLogging ignored = new StacklessLogging(Response.class); Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
237237
{
238238
OutputStream os = client.getOutputStream();
239239

@@ -1669,12 +1669,10 @@ public void testWriteBodyAfterNoBodyResponse() throws Exception
16691669
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
16701670

16711671
String line = in.readLine();
1672-
System.err.println(line);
16731672
assertThat(line, containsString(" 304 "));
16741673
while (true)
16751674
{
16761675
line = in.readLine();
1677-
System.err.println(line);
16781676
if (line == null)
16791677
throw new EOFException();
16801678
if (line.length() == 0)
@@ -1685,7 +1683,6 @@ public void testWriteBodyAfterNoBodyResponse() throws Exception
16851683
assertThat(line, not(containsString("Transfer-Encoding")));
16861684
}
16871685

1688-
System.err.println("---");
16891686
line = in.readLine();
16901687
assertThat(line, containsString(" 304 "));
16911688
while (true)

0 commit comments

Comments
 (0)