Merge pull request #35 from fukamachi/fix/request-raw-body

Replace ENV's raw-body by a circular-stream in case when parsing more than twice.
This commit is contained in:
Eitaro Fukamachi 2018-09-03 18:01:27 +09:00 committed by GitHub
commit d0e8add464
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@
(:import-from :http-body
:parse)
(:import-from :circular-streams
:circular-input-stream
:make-circular-input-stream)
(:import-from :cl-ppcre
:split)
@ -95,7 +96,8 @@
(with-slots (body-parameters raw-body content-length content-type) req
(when raw-body
(setf raw-body (make-circular-input-stream raw-body))
(unless (typep raw-body 'circular-input-stream)
(setf raw-body (make-circular-input-stream raw-body)))
;; POST parameters
(when (and (null body-parameters)
@ -103,6 +105,7 @@
(setf body-parameters
(http-body:parse content-type content-length raw-body))
(file-position raw-body 0)
(setf (getf env :raw-body) raw-body)
(rplacd (last env) (list :body-parameters body-parameters)))))
(setf (request-env req) env)