You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.1 KiB
27 lines
1.1 KiB
(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))
|