From 6d7ef24ee39aea7bebca2d40b93f1ed6de6b1460 Mon Sep 17 00:00:00 2001 From: Olaf Ritter von Ruppert Date: Sat, 18 Sep 2021 14:14:50 +0200 Subject: [PATCH 1/3] Add :PREFER-POST as an request-type to compute-parameter. --- easy-handlers.lisp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/easy-handlers.lisp b/easy-handlers.lisp index 7aefad2..ae19446 100644 --- a/easy-handlers.lisp +++ b/easy-handlers.lisp @@ -118,18 +118,23 @@ 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, :BOTH or :PREFER-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) + (:prefer-post + (lambda (name &optional (request *request*)) + (or (post-parameter name request) + (get-parameter name request)))))) (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*))) + (:prefer-post (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 +204,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 From 22e7888bee04ec7c88361c5bb7706cd85cf68687 Mon Sep 17 00:00:00 2001 From: Olaf Ritter von Ruppert Date: Mon, 20 Sep 2021 12:34:42 +0200 Subject: [PATCH 2/3] easy-handlers.lisp: compute-parameter: new request-type keywords: :POST-OR-GET and GET-OR-POST. --- easy-handlers.lisp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/easy-handlers.lisp b/easy-handlers.lisp index ae19446..9621b6f 100644 --- a/easy-handlers.lisp +++ b/easy-handlers.lisp @@ -118,23 +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, :BOTH or :PREFER-POST." +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) - (:prefer-post - (lambda (name &optional (request *request*)) - (or (post-parameter name request) - (get-parameter name request)))))) + (: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*))) - (:prefer-post (append (post-parameters*) (get-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)) From e3006ce1912274329d678c69dd3de22bb2e48d0c Mon Sep 17 00:00:00 2001 From: Olaf Ritter von Ruppert Date: Mon, 20 Sep 2021 12:39:39 +0200 Subject: [PATCH 3/3] easy-handlers.lisp: compute-parameter: new request-type keywords: :POST-OR-GET and GET-OR-POST. --- request.lisp | 8 ++++++++ 1 file changed, 8 insertions(+) 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