Change middleware definitions from parameters to functions
This commit is contained in:
parent
61a4c177ab
commit
56ef2a853d
3 changed files with 13 additions and 13 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
This middleware handles Trailing Slash in the URL on a GET request.
|
This middleware handles Trailing Slash in the URL on a GET request.
|
||||||
|
|
||||||
`*append-trailing-slash*` redirects the URL to which it added the Trailing Slash if the content was not found. Also, `*trim-trailing-slash*` will remove the Trailing Slash.
|
`append-trailing-slash` redirects the URL to which it added the Trailing Slash if the content was not found. Also, `trim-trailing-slash` will remove the Trailing Slash.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ Example of redirecting a GET request of `/about/me` to `/about/me/`.
|
||||||
(:import-from #:ningle)
|
(:import-from #:ningle)
|
||||||
(:import-from #:lack)
|
(:import-from #:lack)
|
||||||
(:import-from #:lack-mw
|
(:import-from #:lack-mw
|
||||||
#:*append-trailing-slash*))
|
#:append-trailing-slash))
|
||||||
(in-package #:app/main)
|
(in-package #:app/main)
|
||||||
|
|
||||||
(defparameter *raw-app* (make-instance 'ningle:app))
|
(defparameter *raw-app* (make-instance 'ningle:app))
|
||||||
|
@ -23,7 +23,7 @@ Example of redirecting a GET request of `/about/me` to `/about/me/`.
|
||||||
|
|
||||||
(defparameter *app*
|
(defparameter *app*
|
||||||
(lack:builder
|
(lack:builder
|
||||||
*append-trailing-slash*
|
(append-trailing-slash)
|
||||||
*raw-app*))
|
*raw-app*))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ Example of redirecting a GET request of `/about/me/` to `/about/me`.
|
||||||
(:import-from #:ningle)
|
(:import-from #:ningle)
|
||||||
(:import-from #:lack)
|
(:import-from #:lack)
|
||||||
(:import-from #:lack-mw
|
(:import-from #:lack-mw
|
||||||
#:*trim-trailing-slash*))
|
#:trim-trailing-slash))
|
||||||
(in-package #:app/main)
|
(in-package #:app/main)
|
||||||
|
|
||||||
(defparameter *raw-app* (make-instance 'ningle:app))
|
(defparameter *raw-app* (make-instance 'ningle:app))
|
||||||
|
@ -44,7 +44,7 @@ Example of redirecting a GET request of `/about/me/` to `/about/me`.
|
||||||
|
|
||||||
(defparameter *app*
|
(defparameter *app*
|
||||||
(lack:builder
|
(lack:builder
|
||||||
*trim-trailing-slash*
|
(trim-trailing-slash)
|
||||||
*raw-app*))
|
*raw-app*))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
(defpackage #:lack-mw/trailing-slash
|
(defpackage #:lack-mw/trailing-slash
|
||||||
(:use #:cl)
|
(:use #:cl)
|
||||||
(:import-from #:quri)
|
(:import-from #:quri)
|
||||||
(:export #:*trim-trailing-slash*
|
(:export #:trim-trailing-slash
|
||||||
#:*append-trailing-slash*))
|
#:append-trailing-slash))
|
||||||
(in-package #:lack-mw/trailing-slash)
|
(in-package #:lack-mw/trailing-slash)
|
||||||
|
|
||||||
(defun last-string (str)
|
(defun last-string (str)
|
||||||
(subseq str (- (length str) 1)))
|
(subseq str (- (length str) 1)))
|
||||||
|
|
||||||
(defparameter *trim-trailing-slash*
|
(defun trim-trailing-slash ()
|
||||||
(lambda (app)
|
(lambda (app)
|
||||||
(lambda (env)
|
(lambda (env)
|
||||||
(let* ((req-uri (quri:uri (getf env :request-uri)))
|
(let* ((req-uri (quri:uri (getf env :request-uri)))
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
`(301 (:location ,(quri:render-uri red-uri)) ()))
|
`(301 (:location ,(quri:render-uri red-uri)) ()))
|
||||||
response)))))
|
response)))))
|
||||||
|
|
||||||
(defparameter *append-trailing-slash*
|
(defun append-trailing-slash ()
|
||||||
(lambda (app)
|
(lambda (app)
|
||||||
(lambda (env)
|
(lambda (env)
|
||||||
(let* ((req-uri (quri:uri (getf env :request-uri)))
|
(let* ((req-uri (quri:uri (getf env :request-uri)))
|
||||||
|
|
|
@ -7,13 +7,13 @@
|
||||||
#:request)
|
#:request)
|
||||||
(:import-from #:ningle)
|
(:import-from #:ningle)
|
||||||
(:import-from #:lack-mw/trailing-slash
|
(:import-from #:lack-mw/trailing-slash
|
||||||
#:*trim-trailing-slash*
|
#:trim-trailing-slash
|
||||||
#:*append-trailing-slash*))
|
#:append-trailing-slash))
|
||||||
(in-package #:lack-mw-test/trailing-slash)
|
(in-package #:lack-mw-test/trailing-slash)
|
||||||
|
|
||||||
(defparameter *app-without-trailing-slash*
|
(defparameter *app-without-trailing-slash*
|
||||||
(lack:builder
|
(lack:builder
|
||||||
*trim-trailing-slash*
|
(trim-trailing-slash)
|
||||||
(let ((raw-app (make-instance 'ningle:app)))
|
(let ((raw-app (make-instance 'ningle:app)))
|
||||||
(setf (ningle:route raw-app "/") "ok")
|
(setf (ningle:route raw-app "/") "ok")
|
||||||
(setf (ningle:route raw-app "/without/trailing/slash") "ok")
|
(setf (ningle:route raw-app "/without/trailing/slash") "ok")
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
(defparameter *app-with-trailing-slash*
|
(defparameter *app-with-trailing-slash*
|
||||||
(lack:builder
|
(lack:builder
|
||||||
*append-trailing-slash*
|
(append-trailing-slash)
|
||||||
(let ((raw-app (make-instance 'ningle:app)))
|
(let ((raw-app (make-instance 'ningle:app)))
|
||||||
(setf (ningle:route raw-app "/") "ok")
|
(setf (ningle:route raw-app "/") "ok")
|
||||||
(setf (ningle:route raw-app "/something.file") "ok")
|
(setf (ningle:route raw-app "/something.file") "ok")
|
||||||
|
|
Loading…
Reference in a new issue