Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

73 lines (57 sloc) 1.951 kb
This file is a part of Clack package.
Copyright (c) 2011 Eitarow Fukamachi <>
Clack is freely distributable under the LLGPL License.
(clack.util:namespace clack.middleware
(:use :cl)
(:import-from :clack.component
(cl-syntax:use-syntax :annot)
(defclass <middleware> (<component>)
((app :type component-designator
:initarg :app
:reader app))
(:documentation "Class for Clack Middleware."))
(defmethod call-next ((this <middleware>) env)
"Call next middleware or application."
(call (app this) env))
(defmethod wrap ((this <middleware>) app-or-middleware)
"Compose this and given application or middleware instance into one function.
The function takes request plist."
(setf (slot-value this 'app) app-or-middleware)
#'(lambda (env) (call this env)))
@doc:NAME "
Clack.Middleware - Base Class for Clack Middleware.
(in-package :cl-user)
(defpackage clack.middleware.example
(:use :cl :clack)
(:export :<clack-middleware-example>))
(in-package :clack.middleware.example)
(defclass <clack-middleware-example> (<middleware>) ())
(defmethod call ((this <clack-middleware-example>) env)
;; pre-processing `env'
(let ((res (call-next this env)))
;; post-processing `res'
Clack.Middleware is the base class to write Clack Middleware.
All you have to do is to inherit from `<middleware>' and then implement the callback `call' method to do the actual work.
Middleware is similar to ':around' method of CLOS. You can delegate some processes to Application (or next Middleware) to call `call-next'.
@doc:AUTHOR "
Author: Eitarow Fukamachi (
@doc:SEE "
* Clack.Component
Jump to Line
Something went wrong with that request. Please try again.