Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :PREFER-POST as an request-type to compute-parameter. #200

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions easy-handlers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions request.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down