commit
ee22d5783d
@ -0,0 +1,9 @@
|
|||||||
|
(asdf:defsystem #:hunchenhelpers
|
||||||
|
:description "A helper library to simplify hunchentoot"
|
||||||
|
:author "Manx (boku@plum.moe)"
|
||||||
|
:license "X11/MIT"
|
||||||
|
:version "0.1.0"
|
||||||
|
:serial t
|
||||||
|
:depends-on (:hunchentoot)
|
||||||
|
:Components ((:file "package")
|
||||||
|
(:file "main")))
|
@ -0,0 +1,26 @@
|
|||||||
|
(in-package :hunchenhelpers)
|
||||||
|
|
||||||
|
(defun hunchenhost (func uri path &optional content-type)
|
||||||
|
(let ((thing (if (null content-type)
|
||||||
|
(funcall func uri path)
|
||||||
|
(funcall func uri path content-type))))
|
||||||
|
(push thing tbnl:*dispatch-table*)))
|
||||||
|
|
||||||
|
(defun host-file (uri path &optional content-type)
|
||||||
|
(hunchenhost 'tbnl:create-static-file-dispatcher-and-handler uri path content-type))
|
||||||
|
|
||||||
|
(defun host-dir (uri path &optional content-type)
|
||||||
|
(hunchenhost 'tbnl:create-folder-dispatcher-and-handler uri path content-type))
|
||||||
|
|
||||||
|
(defmacro handle (method uri content-type params &body body)
|
||||||
|
"Creates an easy handles for a specific HTTP request method. If the
|
||||||
|
method provided sent from the client isn't correct, return 404 and
|
||||||
|
stop processing the request.
|
||||||
|
|
||||||
|
(handle :get (uri-fun :uri \"/path/to/page\"/) @content-type (args) (body))"
|
||||||
|
`(tbnl:define-easy-handler ,uri ,params
|
||||||
|
(unless (eq ,method (tbnl:request-method*))
|
||||||
|
(setf (tbnl:return-code*) tbnl:+http-not-found+)
|
||||||
|
(tbnl:abort-request-handler))
|
||||||
|
(setf (tbnl:content-type* tbnl:*reply*) ,content-type)
|
||||||
|
,@body))
|
@ -0,0 +1,6 @@
|
|||||||
|
(defpackage #:hunchenhelpers
|
||||||
|
(:nicknames :henh)
|
||||||
|
(:use :cl :hunchentoot)
|
||||||
|
(:export
|
||||||
|
:host-file :host-dir
|
||||||
|
:handle))
|
Loading…
Reference in new issue