aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoin Okay <cbeok@protonmail.com>2020-04-24 18:40:48 -0500
committerCoin Okay <cbeok@protonmail.com>2020-04-24 18:40:48 -0500
commit2aa6bca29e6a2782a789cdf6fc2cfdfbcb06a628 (patch)
treea6acb56d678b5710e5bce588e181a4ab3cbbf054
parent45e0812d602f5c2cae845ba0cb280b94291ed860 (diff)
application/x-www-form-urlencoded decoder
-rw-r--r--decoders.lisp16
-rw-r--r--lazybones.asd9
-rw-r--r--package.lisp7
3 files changed, 30 insertions, 2 deletions
diff --git a/decoders.lisp b/decoders.lisp
index d6bb7d6..9878b44 100644
--- a/decoders.lisp
+++ b/decoders.lisp
@@ -114,7 +114,6 @@ becomes (:content-disposition (:name \"file\" :filename \"mypic.png\"))")
(<<result parts)))
(defun decode-multipart/form-data (stream content-type content-length)
- (declare (ignore content-length))
(let* ((boundary (concatenate 'string "--"
(second (split-sequence:split-sequence #\= content-type))))
(stream (make-instance 'replay-streams:static-text-replay-stream
@@ -122,3 +121,18 @@ becomes (:content-disposition (:name \"file\" :filename \"mypic.png\"))")
(parse stream (<<multipart/form-data boundary))))
(add-decoder "multipart/form-data" #'decode-multipart/form-data)
+
+;;; APPLICATION/X-WWW-FORM-URLENCODED
+
+(defun decode-application/x-www-form-urlencoded (stream content-type content-length)
+ (declare (ignore content-type))
+ (->> (read-body-to-string stream content-length)
+ (split-sequence #\&)
+ (mapcar (lambda (s) (split-sequence #\= s)))
+ (as->* pairs
+ (loop
+ :for (key undecoded) :in pairs
+ :appending (list (make-keyword key)
+ (urldecode undecoded :queryp t))))))
+
+(add-decoder "application/x-www-form-urlencoded" #'decode-application/x-www-form-urlencoded)
diff --git a/lazybones.asd b/lazybones.asd
index 575e342..54c2643 100644
--- a/lazybones.asd
+++ b/lazybones.asd
@@ -6,7 +6,14 @@
:license "AGPLv3"
:version "0.0.1"
:serial t
- :depends-on (#:clack #:jonathan #:alexandria #:split-sequence #:parzival #:cl-fad)
+ :depends-on (#:clack
+ #:jonathan
+ #:alexandria
+ #:split-sequence
+ #:do-urlencode
+ #:arrows
+ #:parzival
+ #:cl-fad)
:components ((:file "package")
(:file "lazybones")
(:file "decoders")))
diff --git a/package.lisp b/package.lisp
index 0bd0c95..102cff9 100644
--- a/package.lisp
+++ b/package.lisp
@@ -26,5 +26,12 @@
(defpackage #:lazybones.decoders
(:use #:cl #:parzival)
+ (:import-from #:split-sequence
+ #:split-sequence)
+ (:import-from #:arrows
+ #:->>
+ #:as->*)
+ (:import-from #:do-urlencode
+ #:urldecode)
(:import-from #:lazybones
#:add-decoder))