Uploaded image for project: 'HttpComponents HttpCore'
  1. HttpComponents HttpCore
  2. HTTPCORE-759

Content-Length missing on null entity request content

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 5.2.2
    • 5.3-alpha1
    • HttpCore

    Description

      When making a POST request with an empty body, the following difference in behaviour was observed.

      In HttpComponents 4.4.x, a null body causes a Content-Length zero header to be added.
      In HttpComponents 5.2.x, a null body causes no Content-Length headers being added.

      While upgrading an Apache Camel application, we noticed that this breaks calls to an upstream IIS server which replies with 411 (Length Required).
      That server expects either a Content-Length 0 or a Transfer-Encoding: chunked header (with a chunk-size of zero) on requests that have a body semantic (POST, PUT).

      As the code currently stands written, if we manually set `Content-Length: 0` a ProtocolException is thrown RequestContent.java:106
      and if we call the constructor with overwrite, this header is removed anyway without being replaced. 

      The previous behaviour (4.x) is documented RequestContent.java:102

       

      A suggested fix: re-add the null check and set Content-Length to zero.

      Attachments

        Activity

          People

            Unassigned Unassigned
            chrysophylax Billy Jaime Beltran
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2h 10m
                2h 10m