Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-5447

(7.0.z) RESTEASY-1365 - HEAD requests always return Content-Length: 0

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 7.0.4.CR1, 7.0.4.GA
    • 7.0.0.CR2
    • REST
    • None
    • Hide

      1. annotate JAX-RS resource method with @GET
      2. have the resource method generate some non-null response content
      3. curl --head <resource uri>

      Show
      1. annotate JAX-RS resource method with @GET 2. have the resource method generate some non-null response content 3. curl --head <resource uri>
    • EAP 7.0.4

    Description

      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.

      • rfc2730 - Content-Length
        •    A server MAY send a Content-Length header field in a response to a
             HEAD request (Section 4.3.2 of [RFC7231]); a server MUST NOT send
             Content-Length in such a response unless its field-value equals the
             decimal number of octets that would have been sent in the payload
             body of a response if the same request had used the GET method.
      • rfc7231 - head
        •    The HEAD method is identical to GET except that the server MUST NOT
             send a message body in the response (i.e., the response terminates at
             the end of the header section).  The server SHOULD send the same
             header fields in response to a HEAD request as it would have sent if
             the request had been a GET, except that the payload header fields
             (Section 3.3) MAY be omitted.

      Attachments

        Issue Links

          Activity

            People

              istudens@redhat.com Ivo Studensky
              rhn-cservice-bbaranow Bartosz Baranowski
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: