Artifacts Associated With Ticket 6afa947d1a92aace
Ticket change [f6b4cabc8a] (rid 154214) by droll on 2017-06-05 20:09:20:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- 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. - foundin initialized to: "http package, 2.8.9"
- is_private initialized to: "0"
- login: "droll"
- priority initialized to: "5 Medium"
- private_contact initialized to: "c7f3b5a0831cb53da82e8d0adc0c229e226e82cc"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "droll"
- subsystem initialized to: "29. http Package"
- title initialized to:
http::geturl : Missing Content-Length header for POST requests
- type initialized to: "Bug"
Ticket change [70a273226d] (rid 200562) by kjnash on 2022-05-10 22:05:17:
- 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. - login: "kjnash"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [da440bfcf5] (rid 200601) by kjnash on 2022-05-12 01:40:23:
- icomment:
Documentation http(n) revised in commit [751f947bc87f6b2f].
- login: "kjnash"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [e8d38f659e] (rid 200616) by kjnash on 2022-05-13 03:01:22:
- login: "kjnash"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Pending"
Ticket change [85931128bd] (rid 201358) by kjnash on 2022-05-30 16:25:31:
- closedate changed to: "2459730.18439811"
- closer changed to: "kjnash"
- login: "kjnash"
- mimetype: "text/plain"
- status changed to: "Closed"