diff --git a/easy-handlers.lisp b/easy-handlers.lisp index 7aefad2..9621b6f 100644 --- a/easy-handlers.lisp +++ b/easy-handlers.lisp @@ -118,18 +118,25 @@ KEY-TYPE)." (defun compute-parameter (parameter-name parameter-type request-type) "Computes and returns the parameter\(s) called PARAMETER-NAME and converts it/them according to the value of PARAMETER-TYPE. -REQUEST-TYPE is one of :GET, :POST, or :BOTH." +REQUEST-TYPE is one of :GET, :POST, :GET-OR-POST, :POST-OR-GET +or :BOTH. If :POST-OR-GET then post parameters are first taken +into account, if :GET-OR-POST then get parameters are prefered. +:BOTH is an alias for :GET-OR-POST." (when (member parameter-type '(list array hash-table)) (setq parameter-type (list parameter-type 'string))) (let ((parameter-reader (ecase request-type (:get #'get-parameter) (:post #'post-parameter) - (:both #'parameter))) + (:both #'parameter) + (:get-or-post #'parameter) + (:post-or-get #'post-or-get-parameter))) (parameters (and (listp parameter-type) (case request-type (:get (get-parameters*)) (:post (post-parameters*)) - (:both (append (get-parameters*) (post-parameters*))))))) + (:both (append (get-parameters*) (post-parameters*))) + (:get-or-post (append (get-parameters*) (post-parameters*))) + (:post-or-get (append (post-parameters*) (get-parameters*))))))) (cond ((atom parameter-type) (compute-simple-parameter parameter-name parameter-type parameter-reader)) ((and (null (cddr parameter-type)) @@ -199,9 +206,10 @@ will be returned by DISPATCH-EASY-HANDLERS in every acceptor. Whether the GET or POST parameter \(or both) will be taken into consideration, depends on REQUEST-TYPE which can -be :GET, :POST, :BOTH, or NIL. In the last case, the value of -DEFAULT-REQUEST-TYPE \(the default of which is :BOTH) will be -used. +be :GET, :POST, :BOTH, :PREFER-POST or NIL. In the last case, the +value of DEFAULT-REQUEST-TYPE \(the default of which is :BOTH) will be +used. The value :PREFER-POST is like :BOTH, but prefers POST +parameters instead of GET parameters. The value of VAR will usually be a string \(unless it resulted from a file upload in which case it won't be converted at all), but if diff --git a/request.lisp b/request.lisp index 74686e7..41deedc 100644 --- a/request.lisp +++ b/request.lisp @@ -487,6 +487,14 @@ case-sensitive." (or (get-parameter name request) (post-parameter name request))) +(defun post-or-get-parameter (name &optional (request *request*)) + "Returns the POST or the GET parameter with name NAME \(a string) - +or NIL if there is none. If both a POST and a GET parameter with the +same name exist the POST parameter is returned. Search is +case-sensitive." + (or (post-parameter name request) + (get-parameter name request))) + (defun handle-if-modified-since (time &optional (request *request*)) "Handles the 'If-Modified-Since' header of REQUEST. The date string is compared to the one generated from the supplied universal time