diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java index 1a021a8985c..78c8c18aa61 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java @@ -19,6 +19,7 @@ import java.io.InputStream; 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; @@ -1637,4 +1638,36 @@ public class ProxyServletTest assertFalse(contentLatch.await(1, TimeUnit.SECONDS)); assertTrue(clientLatch.await(5, TimeUnit.SECONDS)); } + + @ParameterizedTest + @MethodSource("impls") + public void testExpect100ContinueWithReader(Class 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()); + } + } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index e0929a2a191..00575980873 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -1161,17 +1161,23 @@ public class Request implements HttpServletRequest 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 { + // Do not call super to avoid marking this reader as closed, + // but do close the ServletInputStream that can be reopened. in.close(); } }; } + else if (_channel.isExpecting100Continue()) + { + _channel.continue100(_input.available()); + } _inputState = INPUT_READER; return _reader; }