Fixes #1184 - IllegalStateException for HEAD requests responded with 404.

Fixed additional code path for requests with Accept header and non-404 response.
This commit is contained in:
Simone Bordet 2017-02-26 16:20:28 +01:00
parent 1361b31beb
commit daa2a217e3
2 changed files with 27 additions and 1 deletions

View File

@ -160,14 +160,16 @@ public class ErrorHandler extends AbstractHandler
List<String> acceptable=baseRequest.getHttpFields().getQualityCSV(HttpHeader.ACCEPT);
if (acceptable.isEmpty() && !baseRequest.getHttpFields().contains(HttpHeader.ACCEPT))
{
generateAcceptableResponse(baseRequest,request,response,code,message,MimeTypes.Type.TEXT_HTML.asString());
}
else
{
for (String mimeType:acceptable)
{
generateAcceptableResponse(baseRequest,request,response,code,message,mimeType);
if (baseRequest.isHandled())
return;
break;
}
}
baseRequest.setHandled(true);

View File

@ -42,6 +42,7 @@ import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.util.BytesContentProvider;
import org.eclipse.jetty.client.util.FutureResponseListener;
import org.eclipse.jetty.client.util.InputStreamResponseListener;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http2.FlowControlStrategy;
@ -545,6 +546,29 @@ public class HttpClientTest extends AbstractTest
Assert.assertEquals(0, response.getContent().length);
}
@Test
public void testHEADWithAcceptHeaderAndSendError() throws Exception
{
int status = HttpStatus.BAD_REQUEST_400;
start(new HttpServlet()
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
resp.sendError(status);
}
});
ContentResponse response = client.newRequest(newURI())
.method(HttpMethod.HEAD)
.path(servletPath)
.header(HttpHeader.ACCEPT, "*/*")
.send();
Assert.assertEquals(status, response.getStatus());
Assert.assertEquals(0, response.getContent().length);
}
private void sleep(long time) throws IOException
{
try