From 2154ccf238851fe0eff7da33c9792b34d06bbba3 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Tue, 8 Feb 2022 14:04:29 -0600 Subject: added app-state table --- lazybones.lisp | 15 ++++++++++++--- package.lisp | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lazybones.lisp b/lazybones.lisp index cf438cf..0ac07ba 100644 --- a/lazybones.lisp +++ b/lazybones.lisp @@ -60,6 +60,10 @@ is evoked when an ENDPOINT's AUTH slot is T. Endpoints may override this behavor by supplying a function in place of T. A value of NIL means that there is no default authorizer.") + (state-table + :accessor app-state-table + :initform (make-hash-table) + :documentation "A hash table with EQL comparing keys. Used for storing arbitrary application state.") (app-error-response-contents :accessor app-error-response-contents :initform nil @@ -73,6 +77,12 @@ :accessor app-endpoints :initform nil))) +(defun app-state (key &optional (app *app*)) + (gethash key (app-state-table app))) + +(defun (setf app-state) (value key &optional (app *app*)) + (setf (gethash key (app-state-table app)) value)) + (defun error-content (code &optional (app *app*)) (cdr (assoc code (app-error-response-contents app)))) @@ -391,7 +401,6 @@ file. CONTENT-TYPE should be a MIME type string." "*APP*, *RESPONSE* and *REQUEST* should all be defined here." (http-respond code - (or content (default-error-response code)))) + (or content (error-content code)))) + -(defun default-error-response (code &optional (app *app*)) - (cdr (assoc code (app-error-response-contents app)))) diff --git a/package.lisp b/package.lisp index 826ad8a..a2bcfac 100644 --- a/package.lisp +++ b/package.lisp @@ -42,6 +42,7 @@ #:generate-app-documentation #:provision-app #:app + #:app-state #:create-server #:defendpoint #:defendpoint* -- cgit v1.2.3