diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java index 6ad0df3534c..0f356eb5c0a 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java @@ -673,11 +673,16 @@ public class ResourceService // write without headers 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 (written || !(out instanceof HttpOutput)) { // write normally - putHeaders(response, content, content_length); + putHeaders(response, content, written ? -1 : 0); ByteBuffer buffer = content.getIndirectBuffer(); if (buffer != null) BufferUtil.writeTo(buffer, out); @@ -846,6 +851,11 @@ public class ResourceService } } + private boolean isHead(HttpServletRequest request) + { + return "HEAD".equalsIgnoreCase(request.getMethod()); + } + public interface WelcomeFactory { diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java index c76d78958a5..f242949cf74 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java @@ -462,20 +462,28 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory, Welc doGet(request, response); } + @Override + protected void doHead(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException + { + doGet(request, response); + } + /* (non-Javadoc) * @see javax.servlet.http.HttpServlet#doTrace(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @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 - protected void doOptions(HttpServletRequest req, HttpServletResponse resp) + protected void doOptions(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - resp.setHeader("Allow", "GET,HEAD,POST,OPTIONS"); + response.setHeader("Allow", "GET,HEAD,POST,OPTIONS"); } /*