Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 70a273226de550d4d670201758ce120c90289774997fab7ecceaad29a68a8f74
Ticket: 6afa947d1a92aacecdc4e681741d006b63da4e94
http::geturl : Missing Content-Length header for POST requests
User & Date: kjnash on 2022-05-10 22:05:17
Changes

  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"