The clack-cors Reference Manual

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.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 clack-cors

A Clack middleware to set CORS related HTTP headers.

Author

Alexander Artemenko <>

Home Page

https://40ants.com/clack-cors/

Source Control

(GIT https://github.com/40ants/clack-cors)

Bug Tracker

https://github.com/40ants/clack-cors/issues

License

Unlicense

Long Description

<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/)]

Version

0.2.1

Defsystem Dependency

40ants-asdf-system (system).

Dependency

clack-cors/core (system).

Source

clack-cors.asd.


2.2 clack-cors/core

Author

Alexander Artemenko <>

Home Page

https://40ants.com/clack-cors/

Source Control

(GIT https://github.com/40ants/clack-cors)

Bug Tracker

https://github.com/40ants/clack-cors/issues

License

Unlicense

Dependencies
  • log4cl (system).
  • alexandria (system).
  • serapeum (system).
Source

clack-cors.asd.


3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


3.1 Lisp


3.1.1 clack-cors/clack-cors.asd

Source

clack-cors.asd.

Parent Component

clack-cors (system).

ASDF Systems

3.1.2 clack-cors/core/file-type.lisp

Source

clack-cors.asd.

Parent Component

clack-cors/core (system).

Packages

clack-cors.

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 clack-cors

Source

file-type.lisp.

Nickname

clack-cors/core

Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


5.1 Public Interface


5.1.1 Special variables

Special Variable: *default-allowed-headers*

Default value to return as ‘Access-Control-Allow-Headers‘ HTTP header.

Package

clack-cors.

Source

file-type.lisp.

Special Variable: *default-allowed-methods*

Default value to return as ‘Access-Control-Allow-Methods‘ HTTP header.

Package

clack-cors.

Source

file-type.lisp.

Special Variable: *default-allowed-origin*

Default value to return as ‘Access-Control-Allow-Origin‘ HTTP header.

Package

clack-cors.

Source

file-type.lisp.

Special Variable: *default-error-response*

Default value to return if main app will not return a list of three items.

Package

clack-cors.

Source

file-type.lisp.


5.1.2 Ordinary functions

Function: make-cors-middleware (app &key allowed-origin allowed-headers allowed-methods 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.

Package

clack-cors.

Source

file-type.lisp.


5.2 Internals


5.2.1 Ordinary functions

Function: process-cors-middleware (env app access-control allowed-headers allowed-methods error-response)
Package

clack-cors.

Source

file-type.lisp.

Function: value-or-funcall (value env response-headers)
Package

clack-cors.

Source

file-type.lisp.


Appendix A Indexes


A.1 Concepts