Use circular-streams for wrapping raw-body.

This commit is contained in:
Eitaro Fukamachi 2016-10-17 10:35:33 +09:00
parent 4e3dd0b4a8
commit 3940e86e8e
2 changed files with 12 additions and 6 deletions

View file

@ -9,5 +9,6 @@
:license "LLGPL"
:depends-on (:quri
:http-body
:circular-streams
:cl-ppcre)
:components ((:file "src/request")))

View file

@ -5,6 +5,8 @@
:url-decode-params)
(:import-from :http-body
:parse)
(:import-from :circular-streams
:make-circular-input-stream)
(:import-from :cl-ppcre
:split)
(:export :request
@ -79,13 +81,16 @@
(quri:url-decode-params query-string :lenient t))
(rplacd (last env) (list :query-parameters query-parameters))))
;; POST parameters
(with-slots (body-parameters raw-body content-length content-type) req
(when (and (null body-parameters)
raw-body)
(setf body-parameters
(http-body:parse content-type content-length raw-body))
(rplacd (last env) (list :body-parameters body-parameters))))
(when raw-body
(setf raw-body (make-circular-input-stream raw-body))
;; POST parameters
(when (null body-parameters)
(setf body-parameters
(http-body:parse content-type content-length raw-body))
(file-position raw-body 0)
(rplacd (last env) (list :body-parameters body-parameters)))))
(setf (request-env req) env)