Skip to content

Commit

Permalink
Fixes #7117 - Timeout with Expect 100 continue when using ProxyServlet.
Browse files Browse the repository at this point in the history
Now getReader() tests whether it has to send a 100 continue in case getInputStream() is not called.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Nov 8, 2022
1 parent cf7353f commit a6fec78
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.ConnectException;
import java.net.HttpCookie;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -1637,4 +1638,36 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
assertFalse(contentLatch.await(1, TimeUnit.SECONDS));
assertTrue(clientLatch.await(5, TimeUnit.SECONDS));
}

@ParameterizedTest
@MethodSource("impls")
public void testExpect100ContinueWithReader(Class<? extends ProxyServlet> proxyServletClass) throws Exception
{
startServer(new EmptyHttpServlet()
{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException
{
// Calling getReader() should trigger the send of 100 Continue.
IO.copy(request.getReader(), Writer.nullWriter());
}
});
startProxy(proxyServletClass);
startClient();
client.setMaxConnectionsPerDestination(1);

// Perform consecutive requests to test whether recycling of
// the Request on server side messes up 100 Continue handling.
int count = 8;
for (int i = 0; i < count; ++i)
{
ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort())
.path("/" + i)
.headers(headers -> headers.put(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString()))
.body(new BytesRequestContent(new byte[]{'h', 'e', 'l', 'l', 'o'}))
.timeout(5, TimeUnit.SECONDS)
.send();
assertEquals(HttpStatus.OK_200, response.getStatus());
}
}
}
15 changes: 6 additions & 9 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -1161,16 +1161,13 @@ public BufferedReader getReader() throws IOException

if (_reader == null || !encoding.equalsIgnoreCase(_readerEncoding))
{
final ServletInputStream in = getInputStream();
ServletInputStream in = getInputStream();
_readerEncoding = encoding;
_reader = new BufferedReader(new InputStreamReader(in, encoding))
{
@Override
public void close() throws IOException
{
in.close();
}
};
_reader = new BufferedReader(new InputStreamReader(in, encoding));
}
else if (_channel.isExpecting100Continue())
{
_channel.continue100(_input.available());
}
_inputState = INPUT_READER;
return _reader;
Expand Down

0 comments on commit a6fec78

Please sign in to comment.