This is the clack-cors Reference Manual, version 0.2.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 05:35:14 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
clack-cors
A Clack middleware to set CORS related HTTP headers.
Alexander Artemenko <svetlyak.40wt@gmail.com>
(GIT https://github.com/40ants/clack-cors)
Unlicense
<a id="x-28CLACK-CORS-DOCS-2FINDEX-3A-40README-2040ANTS-DOC-2FLOCATIVES-3ASECTION-29"></a>
# clack-cors - A Clack middleware to set CORS related HTTP headers.
<a id="clack-cors-asdf-system-details"></a>
## CLACK-CORS ASDF System Details
* Description: A Clack middleware to set ‘CORS‘ related ‘HTTP‘ headers.
* Licence: Unlicense
* Author: Alexander Artemenko <svetlyak.40wt@gmail.com>
* Homepage: [https://40ants.com/clack-cors/][5c32]
* Bug tracker: [https://github.com/40ants/clack-cors/issues][b14f]
* Source control: [GIT][74db]
* Depends on: [alexandria][8236], [log4cl][7f8b], [serapeum][c41d]
[![](https://github-actions.40ants.com/40ants/clack-cors/matrix.svg?only=ci.run-tests)][1700]
![](http://quickdocs.org/badge/clack-cors.svg)
<a id="x-28CLACK-CORS-DOCS-2FINDEX-3A-3A-40INSTALLATION-2040ANTS-DOC-2FLOCATIVES-3ASECTION-29"></a>
## Installation
You can install this library from Quicklisp, but you want to receive updates quickly, then install it from Ultralisp.org:
“‘
(ql-dist:install-dist "http://dist.ultralisp.org/"
:prompt nil)
(ql:quickload :clack-cors)
“‘
<a id="x-28CLACK-CORS-DOCS-2FINDEX-3A-3A-40USAGE-2040ANTS-DOC-2FLOCATIVES-3ASECTION-29"></a>
## Usage
<a id="x-28CLACK-CORS-3AMAKE-CORS-MIDDLEWARE-20FUNCTION-29"></a>
### [function](58a5) ‘clack-cors:make-cors-middleware‘ app &key (allowed-origin \*default-allowed-origin\*) (allowed-headers \*default-allowed-headers\*) (allowed-methods \*default-allowed-methods\*) (error-response \*default-error-response\*)
Returns a Clack middleware which can be used to override ‘CORS‘ ‘HTTP‘ headers in response.
You can pass arguments ‘ALLOWED-ORIGIN‘, ‘ALLOWED-HEADERS‘ and ‘ALLOWED-METHODS‘ to override corresponding headers.
If given, these arguments are extend headers, returned by the main application. For example, if main application
already returns ‘Access-Control-Allow-Headers‘ with value ‘Content-Type‘, then it will be overwritten with
the value ‘Authorization‘. To implement a smarter logic, pass as an argument a function of two variables - initial
‘env‘ plist and resulting headers ‘plist‘. The function should return a string which will be used
to replace a header value.
Also, you can provide a ‘ERROR-RESPONSE‘ argument which will be used as response
in case if original ‘APP‘ returns response other than a list of three items. This argument
should be a list like this:
“‘
(list 500
(list :Content-Type "application/json")
(list "{\"code\": -1, \"message\": \"Unhandled error.\"}"))
“‘
All arguments can be given as a function of two argument, in this case a function
will be called with Lack’s ‘env‘ plist and a plist of headers returned by the main application.
Most useful keys in the ‘env‘ plist are ‘:REQUEST-METHOD‘ and ‘:REQUEST-URI‘.
<a id="x-28CLACK-CORS-3A-2ADEFAULT-ALLOWED-ORIGIN-2A-20-28VARIABLE-29-29"></a>
### [variable](b975) ‘clack-cors:*default-allowed-origin*‘ nil
Default value to return as ‘Access-Control-Allow-Origin‘ ‘HTTP‘ header.
<a id="x-28CLACK-CORS-3A-2ADEFAULT-ALLOWED-HEADERS-2A-20-28VARIABLE-29-29"></a>
### [variable](9d07) ‘clack-cors:*default-allowed-headers*‘ nil
Default value to return as ‘Access-Control-Allow-Headers‘ ‘HTTP‘ header.
<a id="x-28CLACK-CORS-3A-2ADEFAULT-ALLOWED-METHODS-2A-20-28VARIABLE-29-29"></a>
### [variable](8e7c) ‘clack-cors:*default-allowed-methods*‘ nil
Default value to return as ‘Access-Control-Allow-Methods‘ ‘HTTP‘ header.
<a id="x-28CLACK-CORS-3A-2ADEFAULT-ERROR-RESPONSE-2A-20-28VARIABLE-29-29"></a>
### [variable](7f32) ‘clack-cors:*default-error-response*‘ (500 (:CONTENT-TYPE "application/json")
("{\"code\": -1, \"message\": \"Unhandled error.\"}"))
Default value to return if main app will not return a list of three items.
[5c32]: https://40ants.com/clack-cors/
[74db]: https://github.com/40ants/clack-cors
[1700]: https://github.com/40ants/clack-cors/actions
[b975]: https://github.com/40ants/clack-cors/blob/0000ac4dd3ee6742f42d78415543f9ee9558ef29/src/core.lisp#L18
[9d07]: https://github.com/40ants/clack-cors/blob/0000ac4dd3ee6742f42d78415543f9ee9558ef29/src/core.lisp#L21
[8e7c]: https://github.com/40ants/clack-cors/blob/0000ac4dd3ee6742f42d78415543f9ee9558ef29/src/core.lisp#L24
[7f32]: https://github.com/40ants/clack-cors/blob/0000ac4dd3ee6742f42d78415543f9ee9558ef29/src/core.lisp#L27
[58a5]: https://github.com/40ants/clack-cors/blob/0000ac4dd3ee6742f42d78415543f9ee9558ef29/src/core.lisp#L66
[b14f]: https://github.com/40ants/clack-cors/issues
[8236]: https://quickdocs.org/alexandria
[7f8b]: https://quickdocs.org/log4cl
[c41d]: https://quickdocs.org/serapeum
* * *
###### [generated by [40ANTS-DOC](https://40ants.com/doc/)]
0.2.1
40ants-asdf-system
(system).
clack-cors/core
(system).
clack-cors/core
Alexander Artemenko <svetlyak.40wt@gmail.com>
(GIT https://github.com/40ants/clack-cors)
Unlicense
log4cl
(system).
alexandria
(system).
serapeum
(system).
Files are sorted by type and then listed depth-first from the systems components trees.
clack-cors/core/file-type.lisp
clack-cors/core
(system).
*default-allowed-headers*
(special variable).
*default-allowed-methods*
(special variable).
*default-allowed-origin*
(special variable).
*default-error-response*
(special variable).
make-cors-middleware
(function).
process-cors-middleware
(function).
value-or-funcall
(function).
Packages are listed by definition order.
clack-cors
clack-cors/core
common-lisp
.
*default-allowed-headers*
(special variable).
*default-allowed-methods*
(special variable).
*default-allowed-origin*
(special variable).
*default-error-response*
(special variable).
make-cors-middleware
(function).
process-cors-middleware
(function).
value-or-funcall
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Default value to return as ‘Access-Control-Allow-Headers‘ HTTP header.
Default value to return as ‘Access-Control-Allow-Methods‘ HTTP header.
Default value to return as ‘Access-Control-Allow-Origin‘ HTTP header.
Default value to return if main app will not return a list of three items.
Returns a Clack middleware which can be used to override CORS HTTP headers in response.
You can pass arguments ALLOWED-ORIGIN, ALLOWED-HEADERS and ALLOWED-METHODS to override corresponding headers.
If given, these arguments are extend headers, returned by the main application. For example, if main application
already returns ‘Access-Control-Allow-Headers‘ with value ‘Content-Type‘, then it will be overwritten with
the value ‘Authorization‘. To implement a smarter logic, pass as an argument a function of two variables - initial
‘env‘ plist and resulting headers ‘plist‘. The function should return a string which will be used
to replace a header value.
Also, you can provide a ERROR-RESPONSE argument which will be used as response
in case if original APP returns response other than a list of three items. This argument
should be a list like this:
“‘
(list 500
(list :Content-Type "application/json")
(list "{\"code\": -1, \"message\": \"Unhandled error.\"}"))
“‘
All arguments can be given as a function of two argument, in this case a function
will be called with Lack’s ‘env‘ plist and a plist of headers returned by the main application.
Most useful keys in the ‘env‘ plist are :REQUEST-METHOD and :REQUEST-URI.
Jump to: | F M P V |
---|
Jump to: | F M P V |
---|
Jump to: | *
S |
---|
Jump to: | *
S |
---|
Jump to: | C F P S |
---|
Jump to: | C F P S |
---|