From a455cdc2a15a35900680cbe4f4855803767cd1f0 Mon Sep 17 00:00:00 2001 From: David Botton Date: Sun, 31 Jan 2021 00:42:21 -0500 Subject: [PATCH] prep work on better post method support and future long-polling for better search engine ready files --- clog-connection.lisp | 35 ++++++++++++++++++++++++++--------- tutorial/12-tutorial.lisp | 2 +- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/clog-connection.lisp b/clog-connection.lisp index 042de82..099ed52 100644 --- a/clog-connection.lisp +++ b/clog-connection.lisp @@ -272,16 +272,30 @@ path by querying the browser. See PATH-NAME (CLOG-LOCATION)." (lambda (app) (lambda (env) - (prog1 (funcall app env) - (when (equal (getf env :content-type) - "application/x-www-form-urlencoded") - (process-post env))))) + ;; Check if post method response + (when (equal (getf env :content-type) + "application/x-www-form-urlencoded") + (process-post env)) + + ;; Special handling of "clog paths" + (let ((clog-path (gethash (getf env :path-info) *url-to-boot-file*))) + (cond (clog-path + (let ((file (uiop:subpathname static-root clog-path))) + (print static-root) + (print clog-path) + (format t "Serving Boot File : ~A" file) + (with-open-file (stream file :direction :input + :if-does-not-exist nil) + (let ((string (make-string (file-length stream)))) + (read-sequence string stream) + `(200 (:content-type "text/html") (,string)))))) + + ;; Pass the handling on next rule + (t (funcall app env)))))) (:static :path (lambda (path) - (let ((clog-path (gethash path *url-to-boot-file*))) - (cond ((ppcre:scan "^(?:/clog$)" path) nil) - (clog-path clog-path) - (t path)))) + (cond ((ppcre:scan "^(?:/clog$)" path) nil) + (t path))) :root static-root) (lambda (env) @@ -321,7 +335,10 @@ path by querying the browser. See PATH-NAME (CLOG-LOCATION)." (defun set-clog-path (path boot-file) (if boot-file - (setf (gethash path *url-to-boot-file*) boot-file) + (setf (gethash path *url-to-boot-file*) + (if (eql (char boot-file 0) #\/) + (concatenate 'string "." boot-file) + boot-file)) (remhash path *url-to-boot-file*))) ;;;;;;;;;;;;;;;;;;; diff --git a/tutorial/12-tutorial.lisp b/tutorial/12-tutorial.lisp index 7434681..a2b9cf8 100644 --- a/tutorial/12-tutorial.lisp +++ b/tutorial/12-tutorial.lisp @@ -120,7 +120,7 @@ ;; Setting a "default" path says that any use of an included boot.js ;; file will route to this function, in this case #'on-default - ;; that will deterime if this is coming from the path used in tutorial + ;; that will determine if this is coming from the path used in tutorial ;; 11 - "http://127.0.0.1:8080/tutorial/tut-11.html" and if does ;; use on-tutorial11 and if not say "No Dice!" (set-on-new-window #'on-default :path "default")