Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1365

HEAD requests always return Content-Length: 0

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.0.19.Final
    • 3.0.16.Final
    • jaxrs
    • None

      Per HTTP spec, responses to HEAD requests should include Content-Length header indicating the entity size even though the entity itself is not included in response. Generic javax.servlet.http.HttpServlet.doHead() supports this as well.

      However, RESTEasy skips the entity serialization for HEAD requests and thus returns the wrong Content-Length: 0. In org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse():

            if (jaxrsResponse.getEntity() == null || request.getHttpMethod().equalsIgnoreCase("HEAD"))
            {
               response.setStatus(jaxrsResponse.getStatus());
               commitHeaders(jaxrsResponse, response);
               return;
            }
      

      Note this happens after the resource method already built the response, so all we're saving here is serialization – the heavy lifting of building the response already occurred.

            istudens@redhat.com Ivo Studensky
            pnehrer_jira Peter Nehrer (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: