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:
parent
1361b31beb
commit
daa2a217e3
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue