http::geturl: Documentation discrepancy on -query {}
http::geturl $URL -query {}
sends a get request and not a post request.
The documentation of 8.6.11 is: https://www.tcl-lang.org/man/tcl8.6/TclCmd/http.htm#M29
-query query
This flag causes ::http::geturl to do a POST request...
In this corner case, it does not. It sends a get request.
I suppose, we can not change the behaviour. It might be beneficial to change the wording to say that an empty query sends a get request.
Any comments welcome.
Best regards, Harald
Note: for my personal use, it would be handy to send a post request with empty payload.
Hi Harald,
I've just looked at RFC 7230-3 and I cannot see anything that forbids a POST request with no message body. However, it is an unusual case: do you use custom request headers to modify the state of the server?
The behaviour of http::geturl could be changed, but this is a change of API that might break some existing code, and would require an increase in the major version of the http package.
Fortunately, you can use the existing http::geturl to send POST with an empty body by using the options "-method POST -headers {Content-Length 0}".
-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.
I will modify the man page http(n) to state that the value for -query must be non-empty to cause the POST method.
Best wishes,
Keith.
Documentation http(n) changed:
For -query, to say that an empty query does not sent a POST, see commit [1b15e55938a9b2fc].
For -method, to describe the case of a POST with no request-body, see commit [751f947bc87f6b2f].
Great, I appreciate ! My use-case was the testing of the TCLWS package and what it does, if there is no data.
Thanks, Harald