X-Git-Url: http://git.kpe.io/?p=cl-modlisp.git;a=blobdiff_plain;f=utils.lisp;h=387fa7396c706497a05308637ed4c40eaec900bc;hp=c216022a4e447ff7cf6a9cffe02e67b548cd2ce6;hb=af822a09967eb5334753e5c1207702bf63198313;hpb=cb60460c044d8e4c1270b30acd43853ef4ef8f94 diff --git a/utils.lisp b/utils.lisp index c216022..387fa73 100644 --- a/utils.lisp +++ b/utils.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Dec 2002 ;;;; -;;;; $Id: utils.lisp,v 1.3 2003/07/08 06:40:00 kevin Exp $ +;;;; $Id: utils.lisp,v 1.6 2003/07/11 02:38:00 kevin Exp $ ;;;; ************************************************************************* (in-package #:modlisp) @@ -31,44 +31,48 @@ (write-header-line "Status" "200 OK") (write-header-line "Content-Type" (format-string ,fmt)) (unless ,precomp - (write-string "end" *apache-socket*) - (write-char #\NewLine *apache-socket*)) + (write-string "end" *modlisp-socket*) + (write-char #\NewLine *modlisp-socket*)) (setq ,outstr (with-output-to-string (,stream) - (let ((*apache-socket* (if ,precomp + (let ((*modlisp-socket* (if ,precomp ,stream - *apache-socket*))) + *modlisp-socket*))) (setq ,result (progn ,@body))))) (cond (,precomp (write-header-line "Content-Length" (write-to-string (length ,outstr))) (write-header-line "Keep-Socket" "1") - (write-string "end" *apache-socket*) - (write-char #\NewLine *apache-socket*) - (write-string ,outstr *apache-socket*) - (force-output *apache-socket*) - (set-close-apache-socket nil)) + (write-header-line "Keep-Alive" "timeout=15, max=99") + (write-header-line "Connection" "Keep-Alive") + (write-string "end" *modlisp-socket*) + (write-char #\NewLine *modlisp-socket*) + (write-string ,outstr *modlisp-socket*) + (finish-output *modlisp-socket*) + (setq *close-modlisp-socket* nil)) (t - (set-close-apache-socket t) - (finish-output *apache-socket*))) + (setq *close-modlisp-socket* t) + (finish-output *modlisp-socket*))) ,result))) (defun redirect-to-location (url) (write-header-line "Status" "302 Redirect") (write-header-line "Location" url) - (write-char #\NewLine *apache-socket*) - (set-close-apache-socket t)) + (write-char #\NewLine *modlisp-socket*) + (setq *close-modlisp-socket* t)) (defun output-ml-page (format html) (write-header-line "Status" "200 OK") (write-header-line "Content-Type" (format-string format)) (write-header-line "Content-Length" (format nil "~d" (length html))) (write-header-line "Keep-Socket" "1") - (write-string "end" *apache-socket*) - (write-char #\NewLine *apache-socket*) - (write-string html *apache-socket*) - (set-close-apache-socket nil)) + (write-header-line "Keep-Alive" "timeout=15, max=99") + (write-header-line "Connection" "Keep-Alive") + (write-string "end" *modlisp-socket*) + (write-char #\NewLine *modlisp-socket*) + (write-string html *modlisp-socket*) + (setq *close-modlisp-socket* nil)) (defun output-html-page (str) (output-ml-page :html str)) @@ -76,20 +80,19 @@ (defun output-xml-page (str) (output-ml-page :xml str)) +;; Utility functions for library users + (defun posted-to-alist (posted-string) - "Converts a posted string to an assoc list of variable names and values" + "Converts a posted string to an assoc list of keyword names and values, +\"a=1&bc=demo\" => ((:a . \"1\") (:bc . \"demo\"))" (when posted-string (let ((alist '())) (dolist (name=val (kmrcl:delimited-string-to-list posted-string #\&) (nreverse alist)) (let ((name-val-list (kmrcl:delimited-string-to-list name=val #\=))) - (when (= 2 (length name-val-list)) + (if (= 2 (length name-val-list)) (destructuring-bind (name val) name-val-list (push (cons (kmrcl:ensure-keyword name) (kmrcl:decode-uri-query-string val)) - alist)))))))) - - - - - + alist)) + (cmsg-c :debug "Invalid number of #\= in ~S" name-val-list)))))))