Issue #525 fix blockForContent spin
abort request in bad request handling
This commit is contained in:
parent
bb4b3ef1a9
commit
2a5b120fc3
|
@ -641,6 +641,7 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
|
|||
{
|
||||
// The bad message cannot be handled in the current state, so throw
|
||||
// to hopefull somebody that can handle
|
||||
abort(e);
|
||||
throw new BadMessageException(status,reason);
|
||||
}
|
||||
|
||||
|
|
|
@ -248,6 +248,7 @@ public class HttpChannelOverHttp extends HttpChannel implements HttpParser.Reque
|
|||
{
|
||||
// Need to call onRequest, so RequestLog can reports as much as possible
|
||||
onRequest(_metadata);
|
||||
getRequest().getHttpInput().earlyEOF();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -19,14 +19,12 @@
|
|||
package org.eclipse.jetty.servlet;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -51,21 +49,20 @@ public class PostServletTest
|
|||
{
|
||||
try
|
||||
{
|
||||
byte[] buffer = new byte[4096];
|
||||
|
||||
ServletInputStream in = request.getInputStream();
|
||||
|
||||
int l = in.read(buffer);
|
||||
while (l>0)
|
||||
{
|
||||
// System.err.println("READ: "+new String(buffer,0,l,StandardCharsets.ISO_8859_1));
|
||||
l = in.read(buffer);
|
||||
}
|
||||
|
||||
response.flushBuffer();
|
||||
request.getInputStream().read();
|
||||
}
|
||||
catch (IOException e0)
|
||||
catch (Exception e0)
|
||||
{
|
||||
LOG.warn(e0);
|
||||
try
|
||||
{
|
||||
// this read-call should fail immediately
|
||||
request.getInputStream().read();
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
LOG.warn(e1.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,25 +118,23 @@ public class PostServletTest
|
|||
@Test
|
||||
public void testBadPost() throws Exception
|
||||
{
|
||||
StringBuilder req = new StringBuilder();
|
||||
StringBuilder req = new StringBuilder(16*1024);
|
||||
req.append("POST /post HTTP/1.1\r\n");
|
||||
req.append("Host: localhost\r\n");
|
||||
req.append("Connection: close\r\n");
|
||||
req.append("Transfer-Encoding: chunked\r\n");
|
||||
req.append("\r\n");
|
||||
req.append("6\r\n");
|
||||
req.append("Hello ");
|
||||
// intentionally bad (not a valid chunked char here)
|
||||
for (int i=1024;i-->0;)
|
||||
req.append("xxxxxxxxxxxx");
|
||||
req.append("\r\n");
|
||||
req.append("x\r\n");
|
||||
req.append("World\n");
|
||||
req.append("\r\n");
|
||||
req.append("0\r\n");
|
||||
req.append("\r\n");
|
||||
|
||||
try (StacklessLogging scope = new StacklessLogging(ServletHandler.class))
|
||||
{
|
||||
String resp = connector.getResponses(req.toString());
|
||||
assertThat("resp", resp, containsString("HTTP/1.1 500 "));
|
||||
assertThat("resp", resp, containsString("HTTP/1.1 200 "));
|
||||
assertThat("resp", resp, containsString("chunked"));
|
||||
assertThat("resp", resp, not(containsString("\r\n0\r\n")));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue