Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2019

Content-Length response header for HEAD requests wrong when using BlockingHandler

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 2.2.15.Final
    • 2.2.14.Final
    • None
    • None
    • Hide
      Undertow undertow = Undertow.builder()
              .setHandler(new BlockingHandler(e -> {
                  if (e.getRequestMethod().equals(Methods.HEAD)) {
                      e.setResponseContentLength(123);
                      e.setStatusCode(StatusCodes.OK);
                  }
              }))
              .addHttpListener(8000, "localhost")
              .build();
      undertow.start();
      

      If you then curl the server with a HEAD request, the response shows content length 0 instead of 123.

      $ curl --head http://localhost:8000/
      HTTP/1.1 200 OK
      Connection: keep-alive
      Content-Length: 0
      Date: Sat, 15 Jan 2022 00:37:26 GMT
      

      The exact same code but without the BlockingHandler correctly results in Content-Length: 123 being sent to the client.

      Show
      Undertow undertow = Undertow.builder() .setHandler( new BlockingHandler(e -> { if (e.getRequestMethod().equals(Methods.HEAD)) { e.setResponseContentLength(123); e.setStatusCode(StatusCodes.OK); } })) .addHttpListener(8000, "localhost" ) .build(); undertow.start(); If you then curl the server with a HEAD request, the response shows content length 0 instead of 123. $ curl --head http: //localhost:8000/ HTTP/1.1 200 OK Connection: keep-alive Content-Length: 0 Date: Sat, 15 Jan 2022 00:37:26 GMT The exact same code but without the BlockingHandler correctly results in Content-Length: 123 being sent to the client.

    Description

      If you use the BlockingHandler and then try to set a custom content length for the response to a HEAD request, the value is overwritten and a Content-Length of 0 is returned to the client instead of the explicitly set content length.

       

      Attachments

        Issue Links

          Activity

            People

              flaviarnn Flavia Rainone
              sberler Steven Berler (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: