Browse files

Make POST requests use external-format-out for multipart/form-data.

With this change, POST requests that use multipart/form-data will use
external-format-out for encoding, instead of :latin-1. Without this
change, an attempt to use characters outside the :latin-1 range (e.g,
U+2011, "n-dash") would cause an exception while building the request.

Note: it would be possible to only do this for strings that have
characters that are not standard-char.
  • Loading branch information...
1 parent 1728e3f commit afa31400efd42080477d9c9c64acba4e5e7245e4 @rwiker rwiker committed Oct 2, 2013
Showing with 7 additions and 3 deletions.
  1. +7 −3 request.lisp
10 request.lisp
@@ -86,7 +86,7 @@ depending on the type of CONTENT."
(funcall content stream))
(t (parameter-error "Don't know how to send content ~S to server." content)))))
-(defun make-form-data-function (parameters boundary)
+(defun make-form-data-function (parameters boundary external-format-out)
"Creates and returns a closure which can be used as an argument for
SEND-CONTENT to send PARAMETERS as a `multipart/form-data' request
body using the boundary BOUNDARY."
@@ -106,8 +106,12 @@ body using the boundary BOUNDARY."
(format stream "Content-Disposition: form-data; name=\"~A\"" name)
(cond ((stringp value)
+ (crlf)
+ (format stream "Content-Type: text/plain; charset=~a" external-format-out)
(crlf) (crlf)
- (format stream "~A" value))
+ (setf (flexi-stream-external-format stream) external-format-out)
+ (format stream "~A" value)
+ (setf (flexi-stream-external-format stream) +latin-1+)
((and (listp value)
(first value)
(not (stringp (first value))))
@@ -499,7 +503,7 @@ PARAMETERS will not be used."
(setq parameters-used-p t)
(cond ((or form-data file-parameters-p)
(let ((boundary (format nil "----------~A" (make-random-string))))
- (setq content (make-form-data-function parameters boundary)
+ (setq content (make-form-data-function parameters boundary external-format-out)
content-type (format nil "multipart/form-data; boundary=~A" boundary)))
(unless (or file-parameters-p content-length-provided-p)
(setq content-length (or content-length t))))

0 comments on commit afa3140

Please sign in to comment.