aboutsummaryrefslogtreecommitdiff
path: root/lazybones-hunchentoot.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lazybones-hunchentoot.lisp')
-rw-r--r--lazybones-hunchentoot.lisp43
1 files changed, 43 insertions, 0 deletions
diff --git a/lazybones-hunchentoot.lisp b/lazybones-hunchentoot.lisp
index 1e62b85..8f9b604 100644
--- a/lazybones-hunchentoot.lisp
+++ b/lazybones-hunchentoot.lisp
@@ -57,10 +57,15 @@ keyword or a string and VALUE is a string."
HEADER-NAME can be a keyword or a string."
(h:header-in header-name request))
+(defun request-cookie (name &optional (request *request*))
+ "Returns the cookie with NAME sent with the REQUEST"
+ (h:cookie-in name request))
+
(defun request-method (&optional (request *request*))
"Returns a keyword representing the http method of the request."
(h:request-method request))
+
(defparameter +hunchentoot-pre-decoded-content-types+
'("multipart/form-data" "application/x-www-form-urlencoded"))
@@ -108,6 +113,44 @@ the value of the Content-Type request header."
collect (alexandria:make-keyword k)
collect value))
+;;; HTTP RESPONSE ACCESSORS
+
+(defun response-code (&optional (response *response*))
+ "Access the return code of the resposne. Return code should be an integer."
+ (h:return-code response))
+
+(defun (setf response-code) (code &optional (response *response*))
+ (setf (h:return-code response) code))
+
+(defun resonse-header (name &optional (response *response*))
+ "Access the response header that has NAME, which can be a keyword (recommended) or a string."
+ (h:header-out name response))
+
+(defun (setf response-header) (value name &optional (response *response*))
+ (setf (h:header-out name response) value))
+
+(defun response-cookie (name &optional (response *response*))
+ "Access the cookie with NAME in the response object."
+ (h:cookie-out name response))
+
+(defun (setf response-cookie) (value name &optional (response *response*))
+ (a:if-let (extant-cookie (assoc name (h:cookies-out response) :test #'string=))
+ (setf (cdr extant-cookie) value)
+ (cadar (setf (h:cookies-out response)
+ (cons (cons name value) (h:cookies-out response))))))
+
+(defun http-respond (code content)
+ (setf (response-code) code
+ (response-header :content-type) (or (response-header :content-type content-type)
+ (when (pathnamep content)
+ (h:mime-type content))
+ (default-content-type *app*)
+ (error "Content Type Not Set")))
+ (if (pathnamep content)
+ (h:handle-static-file content)
+ content))
+
+
;;; Hunchentoot Acceptor Subclass
(defclass lazybones-acceptor (h:acceptor)