(in-package #:lazybones.decoders) (defun read-body-to-string (stream content-length) "Reads CONTENT-LENGTH characters from STREAM and returns a string." (let ((string (make-string content-length))) (read-sequence string stream) string)) ;;; JSON DECODER (defun decode-json-body (stream content-type content-length) "Reads LEN characters from stream and decodes them as JSON, returning a PLIST" (declare (ignore content-type)) (jonathan:parse (read-body-to-string stream content-length))) (add-decoder "application/json" #'decode-json-body) ;;; MULTIPART/FORM-DATA DECODER (defun butlast-to-string (res) (map 'string 'identity (butlast res))) (defun make-keyword (str) (read-from-string (format nil ":~a" str))) (defun write-image-to-tmp-file (body) (cl-fad:with-output-to-temporary-file (out-file :element-type '(unsigned-byte 8)) (loop :for char :across body :do (write-byte (char-int char) out-file)))) (defun dump-stream-to-text (stream) (with-output-to-string (out) (loop :for char = (read-char stream nil nil) :while char :do (write-char char out)))) (<