diff --git a/scheme/httpd/handlers.scm b/scheme/httpd/handlers.scm index 0b29ac9..81bdeaa 100644 --- a/scheme/httpd/handlers.scm +++ b/scheme/httpd/handlers.scm @@ -51,11 +51,20 @@ (string=? hostname (string-trim (get-header (request-headers req) 'host)))) handler default-handler)) +(define (get-header headers tag) + (cond + ((assq tag headers) => cdr) + (else + (http-error (status-code bad-request) #f + (string-append "Request did not contain " + (symbol->string tag) + " header"))))) + ;; selects handler according to path-prefix ;; if path-prefix matches, handler is called without the path-prefix (define (make-path-prefix-handler path-prefix handler default-handler) (lambda (path req) - (if (string=? path-prefix (car path)) + (if (and (pair? path) (string=? path-prefix (car path))) (handler (cdr path) req) (default-handler path req))))