From 4e2d9a3a85f281c45f7036ae62430bf0cc909a11 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Wed, 16 Feb 2022 17:34:41 -0600 Subject: allowing get endpoints to respond to head requests --- lazybones-hunchentoot.lisp | 2 +- lazybones.lisp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lazybones-hunchentoot.lisp b/lazybones-hunchentoot.lisp index f404eb6..d752238 100644 --- a/lazybones-hunchentoot.lisp +++ b/lazybones-hunchentoot.lisp @@ -45,7 +45,7 @@ ;; if no endpoint was found, call next method. finally (let ((lzb:*request* request) (lzb:*response* h:*reply*)) - (return (lzb:http-err 404)))) + (return (lzb:http-err nil 404)))) (lzb::http-error (http-error) (let ((lzb:*request* request) (lzb:*response* h:*reply*)) diff --git a/lazybones.lisp b/lazybones.lisp index c7be8d8..66192a2 100644 --- a/lazybones.lisp +++ b/lazybones.lisp @@ -195,6 +195,10 @@ list of values, in the case of success, or NIL in the case of failure." (request-method request) (request-routekey request))) +(defun method-match-for-dispatch-p (req-method ep-method) + "Either the arguments compare EQ or the first is :HEAD and the second is :GET." + (or (eq req-method ep-method) + (and (eq :head req-method) (eq :get ep-method)))) (defun find-endpoint-matching-key (app method key) "Returns a list. NIL represents failure to find match. @@ -203,7 +207,7 @@ Otherwise the result is (ENDPOINT . ARGS) where ENDPOINT is an endpoint instanceq and ARGS is a list of arguments to pass to ENDPOINT's handler function." (loop for endpoint in (app-endpoints app) - for match = (and (eql method (endpoint-method endpoint)) + for match = (and (method-match-for-dispatch-p method (endpoint-method endpoint)) (matches-routekey-p (endpoint-dispatch-pattern endpoint) key)) when match return (cons endpoint (when (listp match) match)))) -- cgit v1.2.3