tkf / emacs-request

Request.el -- Easy HTTP request for Emacs Lisp
http://tkf.github.com/emacs-request/
GNU General Public License v3.0
629 stars 93 forks source link

adds support for curl "<" #222

Closed rfaulhaber closed 1 year ago

rfaulhaber commented 1 year ago

Okay so this is a very nuanced enhancement.

So curl(1) says in the section about the --form flag:

To force the 'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field from a file.

Consider the difference between:

echo 'hello world' | curl https://httpbin.org/post -F "request=@-;" 

and

echo 'hello world' | curl https://httpbin.org/post -F "request=<-;" 

Before this PR, request by default sends all files using @. By specifying :use-contents t when uploading a file, it'll generate the curl --form argument to use < instead. So the roughly equivalent Emacs Lisp code would be:

(request "https://httpbin.org/post"
  :type "POST"
  :sync t
  :files '(("request" . ("request" :data "hello world" :use-contents t)))
  :parser 'buffer-string)

This has to be opted into specifically. The other :files forms default to using @.

dickmao commented 1 year ago

Word.