Skip to content
Tcl Source Code History Of Ticket 6afa947d1a92aace
Login

History Of Ticket 6afa947d1a92aace

Artifacts Associated With Ticket 6afa947d1a92aace

  1. Ticket change [f6b4cabc8a] (rid 154214) by droll on 2017-06-05 20:09:20:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      HTTP POST requests require a Content-Length header if they don't use chunked encoding.
      
      The http::geturl command doesn't provide the Content-Length header if it performs a POST requests with an empty body/query. This is certainly a specific situation, however HTTP post requests with empty body/query are legal requests. However, a missing Content-Length header may create misunderstandings on the server side (e.g. seen with Mongoose 6.4).
      
      The following code lines demonstrate that the Content-Length header is missing for POST requests if the body/query is missing or empty. The code redefines the 'puts' command to print the data transferred through the socket on the standard output.
      
      package require http
      #-> 2.8.9
      
      rename puts puts_orig
      proc puts {args} {
      	::puts_orig stdout "#Std -> [lindex $args end]"
      	::puts_orig {*}$args
      }
      
      http::geturl http://192.168.1.21:8083/JS/Run/zway.controller.data.softwareRevisionVersion.value -method POST
      #Std -> POST /JS/Run/zway.controller.data.softwareRevisionVersion.value HTTP/1.1
      #Std -> Host: 192.168.1.21:8083
      #Std -> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 10.0) http/2.8.9 Tcl/8.6.4
      #Std -> Connection: close
      #Std -> Accept: */*
      #Std -> Accept-Encoding: gzip,deflate,compress
      
      http::geturl http://192.168.1.21:8083/JS/Run/zway.controller.data.softwareRevisionVersion.value -method POST -query ""
      #Std -> POST /JS/Run/zway.controller.data.softwareRevisionVersion.value HTTP/1.1
      #Std -> Host: 192.168.1.21:8083
      #Std -> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 10.0) http/2.8.9 Tcl/8.6.4
      #Std -> Connection: close
      #Std -> Accept: */*
      #Std -> Accept-Encoding: gzip,deflate,compress
      
      http::geturl http://192.168.1.21:8083/JS/Run/zway.controller.data.softwareRevisionVersion.value -method POST -query "Hello"
      #Std -> POST /JS/Run/zway.controller.data.softwareRevisionVersion.value HTTP/1.1
      #Std -> Host: 192.168.1.21:8083
      #Std -> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 10.0) http/2.8.9 Tcl/8.6.4
      #Std -> Connection: close
      #Std -> Accept: */*
      #Std -> Accept-Encoding: gzip,deflate,compress
      #Std -> Content-Type: application/x-www-form-urlencoded
      #Std -> Content-Length: 5
      #Std -> 
      #Std -> Hello
      
      It would be good to fix the http::geturl command in a way that the 'Content-Length' header is also provided for POST requests with empty/missing bodies/queries.
      
    5. foundin initialized to: "http package, 2.8.9"
    6. is_private initialized to: "0"
    7. login: "droll"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "c7f3b5a0831cb53da82e8d0adc0c229e226e82cc"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "droll"
    14. subsystem initialized to: "29. http Package"
    15. title initialized to:
      http::geturl : Missing Content-Length header for POST requests
      
    16. type initialized to: "Bug"
  2. Ticket change [70a273226d] (rid 200562) by kjnash on 2022-05-10 22:05:17:

    1. icomment:
      Hi Andreas,
      
      You appear to be using "-method POST" to work around the issue that http::geturl treats "-query {}" as a GET not a POST (see also bug [15e4bd83c28d0a]).
      
      The man page http(n) states:
      
      <verbatim>
          -method type
              Force the HTTP request method to type. ::http::geturl will auto-select GET, POST or HEAD based on other options, but this option enables choices like PUT and DELETE for webdav support.
      </verbatim>
      
      The option -method allows the caller to override the method that would otherwise be selected by http::geturl.  This option gives the script the power to send nonsense requests.  For example, the options "-query foo -method GET" will send a GET with a request body, although RFC 7231 states:
      
      <verbatim>
         A payload within a GET request message has no defined semantics;
         sending a payload body on a GET request might cause some existing
         implementations to reject the request.
      </verbatim>
      
      When using option -method, it is the responsibility of the caller to choose arguments such that the request is not nonsense.  In general it is not possible for http::geturl to guess what the caller intends.  If there were no other way to send a POST without a request body, I would attempt to adapt http::geturl. However, there is a solution and so I propose to amend the man page to clarify the use of option -method and mention this specific case:
      
      <verbatim>
      It is the caller's responsibility to ensure that the headers and request body (if any) conform to the requirements of the method.  For example if using -method POST to send a POST with an empty request body, the caller must also supply the option "-headers {Content-Length 0}".
      </verbatim>
      
      Best wishes,
      
      Keith Nash.
      
    2. login: "kjnash"
    3. mimetype: "text/x-fossil-wiki"
  3. Ticket change [da440bfcf5] (rid 200601) by kjnash on 2022-05-12 01:40:23:

    1. icomment:
      Documentation http(n) revised in commit [751f947bc87f6b2f].
      
    2. login: "kjnash"
    3. mimetype: "text/x-fossil-wiki"
  4. Ticket change [e8d38f659e] (rid 200616) by kjnash on 2022-05-13 03:01:22:

    1. login: "kjnash"
    2. mimetype: "text/plain"
    3. resolution changed to: "Fixed"
    4. status changed to: "Pending"
  5. Ticket change [85931128bd] (rid 201358) by kjnash on 2022-05-30 16:25:31:

    1. closedate changed to: "2459730.18439811"
    2. closer changed to: "kjnash"
    3. login: "kjnash"
    4. mimetype: "text/plain"
    5. status changed to: "Closed"