summaryrefslogtreecommitdiff
path: root/mulkcms-hunchentoot.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'mulkcms-hunchentoot.lisp')
-rw-r--r--[-rwxr-xr-x]mulkcms-hunchentoot.lisp43
1 files changed, 38 insertions, 5 deletions
diff --git a/mulkcms-hunchentoot.lisp b/mulkcms-hunchentoot.lisp
index c5fa908..4300871 100755..100644
--- a/mulkcms-hunchentoot.lisp
+++ b/mulkcms-hunchentoot.lisp
@@ -14,14 +14,46 @@
(not (directory-pathname-p file))
(lambda () (handle-static-file file)))))
+(defun handle-authorization-page ()
+ (hunchentoot:require-authorization "MulkCMS"))
+
(defun dispatch-mulkcms-request (request)
(let* ((relative-path (subseq (script-name request) 1))
(mulkcms::*use-ssl-p* (equal (header-in* :x-use-ssl)
- "true")))
- (mulkcms::find-request-handler relative-path
- (append (get-parameters*)
- (post-parameters*))
- (header-in* :accept-language))))
+ "true"))
+ (mulkcms::*real-remote-addr*
+ (hunchentoot:real-remote-addr))
+ (mulkcms::*user-agent*
+ (hunchentoot:user-agent))
+ (mulkcms::*request-method*
+ (hunchentoot:request-method*))
+ (mulkcms::*headers*
+ (hunchentoot::headers-in*)))
+ (multiple-value-bind
+ (mulkcms::*user-name* mulkcms::*password*)
+ (hunchentoot:authorization)
+ (let ((handler (mulkcms::find-request-handler relative-path
+ (append (get-parameters*)
+ (post-parameters*))
+ (header-in* :accept-language))))
+ (and handler
+ (lambda ()
+ (let ((result (funcall handler)))
+ (typecase result
+ (cons
+ (when-let (content-type (getf result :content-type))
+ (setf (hunchentoot:content-type*) content-type))
+ (when-let (headers (getf result :headers))
+ (dolist (header headers)
+ (setf (hunchentoot:header-out (car header))
+ (cdr header))))
+ (when-let (return-code (getf result :return-code))
+ (setf (hunchentoot:return-code*) return-code)
+ ;;(hunchentoot:abort-request-handler)
+ )
+ (getf result :body))
+ (t
+ result)))))))))
(defun setup-handlers ()
(setq *dispatch-table*
@@ -42,5 +74,6 @@
(setq *acceptor* (make-instance 'hunchentoot:easy-acceptor
:port *server-port*
:address *server-address*))
+ (setq mulkcms::*authorization-page-handler* #'handle-authorization-page)
(hunchentoot:start *acceptor*))