Skip to content

Commit

Permalink
Merge pull request #170 from ajberkley/ajb/fix-multipart-form-data
Browse files Browse the repository at this point in the history
Fix multipart/form-data behavior when user specifies content-type
  • Loading branch information
ajberkley committed Mar 23, 2024
2 parents 3f53744 + d6c34d9 commit b658412
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/backend/usocket.lisp
Expand Up @@ -565,12 +565,12 @@
(write-header* :proxy-authorization proxy-authorization))))))
(cond
(multipart-p
(write-header* :content-type (format nil "~A; boundary=~A"
(or content-type "multipart/form-data")
boundary))
(write-header :content-type (format nil "~A; boundary=~A"
(or content-type "multipart/form-data")
boundary))
(unless chunkedp
(write-header* :content-length
(multipart-content-length content boundary))))
(write-header :content-length
(multipart-content-length content boundary))))
(form-urlencoded-p
(write-header* :content-type "application/x-www-form-urlencoded")
(unless chunkedp
Expand Down
17 changes: 17 additions & 0 deletions t/dexador.lisp
Expand Up @@ -291,6 +291,23 @@
(ok (eql code 200))
(ok (equal body
(format nil "title: Road to Lisp~%body: \"Within a couple weeks of learning Lisp I found programming in any other language unbearably constraining.\" -- Paul Graham, Road to Lisp~2%")))))
(testing "multipart-boundary-added"
(multiple-value-bind (body code)
(dex:post (localhost)
:content `(("title" . "Road to Lisp")
("body" . ,(asdf:system-relative-pathname :dexador #P"t/data/quote.txt"))))
(ok (eql code 200))
(ok (equal body
(format nil "title: Road to Lisp~%body: \"Within a couple weeks of learning Lisp I found programming in any other language unbearably constraining.\" -- Paul Graham, Road to Lisp~2%")))))
(testing "multipart-boundary-test-added-even-if-content-type-specified"
(multiple-value-bind (body code)
(dex:post (localhost)
:headers '((:content-type . "multipart/form-data"))
:content `(("title" . "Road to Lisp")
("body" . ,(asdf:system-relative-pathname :dexador #P"t/data/quote.txt"))))
(ok (eql code 200))
(ok (equal body
(format nil "title: Road to Lisp~%body: \"Within a couple weeks of learning Lisp I found programming in any other language unbearably constraining.\" -- Paul Graham, Road to Lisp~2%")))))
(testing "upload"
(multiple-value-bind (body code)
(dex:post (localhost "/upload")
Expand Down

0 comments on commit b658412

Please sign in to comment.