From 88c50310089d175a7da9305d666c99cd35cd6796 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 4 Feb 2022 07:01:03 -0600 Subject: removing old modules --- decoders.lisp | 79 ----------------------------------------------------------- fs-serve.lisp | 42 ------------------------------- 2 files changed, 121 deletions(-) delete mode 100644 decoders.lisp delete mode 100644 fs-serve.lisp diff --git a/decoders.lisp b/decoders.lisp deleted file mode 100644 index 7f581a5..0000000 --- a/decoders.lisp +++ /dev/null @@ -1,79 +0,0 @@ -;;;; lazybones.decoders package. - -(in-package #:lazybones.decoders) - -;;; HELPERS - -(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)) - - -(defun binary-content-p (content-type) - (or (alexandria:starts-with-subseq "image" content-type) - (alexandria:starts-with-subseq "audio" content-type) - (and (alexandria:starts-with-subseq "application" content-type) - (not (equal content-type "application/json"))) - (alexandria:starts-with-subseq "video" content-type))) - - -(defun butlast-to-string (res) - (map 'string 'identity (butlast res))) - -(defun make-keyword (str) - (read-from-string (format nil ":~a" str))) - -(defun write-binary-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)))) - -;;; PLAIN TEXT DECODER - -(defun decode-text/plain (stream content-type content-length) - (declare (ignore content-type)) - (read-body-to-string stream content-length)) - -(add-decoder "text/plain" #'decode-text/plain) - - -;;; JSON DECODER - -(defun decode-application/json (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-application/json) - - -;;; MULTIPART/FORM-DATA DECODER - -;; Temporarily justing the hunchentoot post-parameter feature -(add-decoder "multipart/form-data" - (lambda (&rest ignore) - (declare (ignore ignore)) - (loop :for (k . v) :in (hunchentoot:post-parameters*) - :when (and (listp v) (= 3 (length v))) - :collect (list :name k - :body (first v) - :filename (second v) - :content-type (third v)) - :collect (list :name k :body v)))) - -;;; 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/fs-serve.lisp b/fs-serve.lisp deleted file mode 100644 index 169778d..0000000 --- a/fs-serve.lisp +++ /dev/null @@ -1,42 +0,0 @@ -(in-package #:lazybones.fs-serve) - -(defun register-many (mime-prefix config &optional (reader 'read-file-into-string)) - (dolist (entry config) - (if (stringp entry) - (register-file-handler-config entry - (concatenate 'string mime-prefix entry) - reader) - (let ((mtype (concatenate 'string mime-prefix (car entry)))) - (dolist (ext (cdr entry)) - (register-file-handler-config ext mtype reader)))))) - -(defparameter +image-mimetypes+ - '("png" - "bmp" - ("jpeg" "jpeg" "jpg" "jfif" "pjpeg" "pjp") - "apng" - "gif" - ("x-icon" "ico" "cur") - ("svg+xml" "svg") - ("tiff" "tiff" "tif") - "webp" - ) - "Each entry in the list is either a string EXT that will be used to - insert image/EXT mimetype for file extension EXT, or, is a - list (IMGTYPE . EXTENSIONS) and will prodeuce a separate entry for - each of the list EXTENSIONS") - -(register-many "image/" +image-mimetypes+ 'read-file-into-byte-vector) - -(defparameter +text-mimetypes+ - '(("plain" "txt" "csv" "tsv" "org" "md" - "lisp" "py" "el" "c" "java" "scm" "rb" "rs" "cpp" - "hx") - "css" - ("html" "html" "htm") - ("javascript" "js"))) - -(register-many "text/" +text-mimetypes+) - - - -- cgit v1.2.3