Issue #5214 - Use known content_length when in HEAD mode
+ Adding DefaultServlet.doHead() to avoid servlet wrapping + Making ResourceService HEAD aware Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
eba360f662
commit
dcb06d3c35
|
@ -673,11 +673,16 @@ public class ResourceService
|
||||||
// write without headers
|
// write without headers
|
||||||
content.getResource().writeTo(out, 0, content_length);
|
content.getResource().writeTo(out, 0, content_length);
|
||||||
}
|
}
|
||||||
|
// we are working with a HEAD request
|
||||||
|
else if (isHead(request) && content_length > 0)
|
||||||
|
{
|
||||||
|
putHeaders(response, content, content_length);
|
||||||
|
}
|
||||||
// else if we can't do a bypass write because of wrapping
|
// else if we can't do a bypass write because of wrapping
|
||||||
else if (written || !(out instanceof HttpOutput))
|
else if (written || !(out instanceof HttpOutput))
|
||||||
{
|
{
|
||||||
// write normally
|
// write normally
|
||||||
putHeaders(response, content, content_length);
|
putHeaders(response, content, written ? -1 : 0);
|
||||||
ByteBuffer buffer = content.getIndirectBuffer();
|
ByteBuffer buffer = content.getIndirectBuffer();
|
||||||
if (buffer != null)
|
if (buffer != null)
|
||||||
BufferUtil.writeTo(buffer, out);
|
BufferUtil.writeTo(buffer, out);
|
||||||
|
@ -846,6 +851,11 @@ public class ResourceService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isHead(HttpServletRequest request)
|
||||||
|
{
|
||||||
|
return "HEAD".equalsIgnoreCase(request.getMethod());
|
||||||
|
}
|
||||||
|
|
||||||
public interface WelcomeFactory
|
public interface WelcomeFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -462,20 +462,28 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory, Welc
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doHead(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException
|
||||||
|
{
|
||||||
|
doGet(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see javax.servlet.http.HttpServlet#doTrace(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
* @see javax.servlet.http.HttpServlet#doTrace(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
protected void doTrace(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException
|
||||||
{
|
{
|
||||||
resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
|
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
|
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException
|
throws ServletException, IOException
|
||||||
{
|
{
|
||||||
resp.setHeader("Allow", "GET,HEAD,POST,OPTIONS");
|
response.setHeader("Allow", "GET,HEAD,POST,OPTIONS");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue