edicl / drakma

HTTP client written in Common Lisp
http://edicl.github.io/drakma/
249 stars 59 forks source link

Can not send nil values in multipart/form-data. #101

Closed wnortje closed 4 years ago

wnortje commented 4 years ago

POST requests fail when content-type is multipart/form-data and one of the parameters have a nil value. This is a problem when you need to send one parameter with only a name and another which is a file because then Content-Type: application/x-www-form-urlencoded is not an option.

This call

(DRAKMA:HTTP-REQUEST 
          "http://requestbin.net/r/19foq301"
          :METHOD :POST
          :PARAMETERS '(("comment" . nil)) 
          :form-data t)

fails at DRAKMA::MAKE-FORM-DATA-FUNCTION with the condition

Don't know what to do with name/value pair ("comment" . NIL) in multipart/form-data body.
   [Condition of type DRAKMA:PARAMETER-ERROR]
wnortje commented 4 years ago

HI @stassats Thanks for the quick fix. This unfortunately breaks Hunchentoot. [2020-04-08 07:23:47 [ERROR]] While parsing multipart/form-data parameters: Input timeout on #<BASIC-TCP-STREAM ISO-8859-1 (SOCKET/7) #x302006658FCD>

I think the RFC requires a blank line after the header field and the closing delimiter.

------------4h1jHzjTkkvVWfn9AaeE7jOqSM0252bvHhZQryRhXedohriVq8
Content-Disposition: form-data; name="more"

------------4h1jHzjTkkvVWfn9AaeE7jOqSM0252bvHhZQryRhXedohriVq8--

This fixes it

((null value)
 (crlf))
stassats commented 4 years ago

Right.