Merged branch 'jetty-10.0.x' into 'jetty-11.0.x'.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2022-11-09 12:17:44 +01:00
commit 40e79c88ab
No known key found for this signature in database
GPG Key ID: 1677D141BCF3584D
2 changed files with 40 additions and 1 deletions

View File

@ -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<? 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());
}
}
}

View File

@ -1158,17 +1158,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;
}