The cl-cookie Reference Manual

This is the cl-cookie Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 04:47:48 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

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


2.1 cl-cookie

HTTP cookie manager

Author

Eitaro Fukamachi

License

BSD 2-Clause

Long Description

# CL-Cookie

[![Build Status](https://travis-ci.org/fukamachi/cl-cookie.svg?branch=master)](https://travis-ci.org/fukamachi/cl-cookie)

HTTP cookie manager for Common Lisp.

Key features include:

- Create ‘cookie‘ struct instances with ‘make-cookie‘ and the following properties: ‘name‘, ‘value‘, ‘path‘, ‘domain‘, ‘origin-host‘, ‘expires‘, ‘max-age‘, ‘same-site‘, ‘partitioned‘, ‘secure-p‘, ‘httponly-p‘. The ‘creation-timestamp‘ attribute is set automatically at creation time. - Compare cookies with ‘cookie=‘ and ‘cookie-equal‘.
- Convert ‘Set-Cookie‘ header string into ‘cookie‘ instance with ‘parse-set-cookie-headers‘.
- Serialize ‘cookie‘ instances into header strings with ‘write-cookie-header‘ and ‘write-set-cookie-header‘.
- Create ‘cookie-jar‘ struct instances with ‘make-cookie-jar‘ which allows managing of multiple cookies. You can add multiple cookies to a cookie-jar with ‘merge-cookies‘, or match cookies of certain ‘host‘ and ‘path‘ with ‘cookie-jar-host-cookies‘.
- Sanity check for cookie attributes in ‘make-cookie‘, ‘parse-set-cookie-header‘, ‘write-set-cookie-header‘. Can be turned off by setting ‘*sanity-check*‘ or ‘sanity-check‘ parameter (in ‘make-cookie‘ and ‘parse-set-cookie-header‘) to ‘nil‘.

## Usage

### make-cookie (&key name value path domain origin-host expires max-age same-site partitioned secure-p httponly-p)
“‘common-lisp
(defparameter *cookie*
(cl-cookie:make-cookie
:name "SID"
:value "31d4d96e407aad42"
:origin-host "example.com"
:path "/api/"
:domain ".example.com"
:partitioned t
:httponly-p t
:secure-p t
:expires (encode-universal-time 6 22 19 25 1 2002 0)
:max-age 3600 ;; max-age takes precedence over expires
:same-site "Strict"))
;=> *COOKIE*

*cookie*
;=> #S(COOKIE :NAME "SID" :VALUE "31d4d96e407aad42" :EXPIRES 3220975326 :PATH "/api/"
; :DOMAIN ".example.com" :SAME-SITE "Strict" :MAX-AGE 3600 :PARTITIONED T
; :SECURE-P T :HTTPONLY-P T :ORIGIN-HOST "example.com" :CREATION-TIMESTAMP 3921465733)
“‘

### write-set-cookie-header (cookie &optional stream)

“‘common-lisp
(cl-cookie:write-set-cookie-header *cookie*)
;=> "SID=31d4d96e407aad42; Expires=Fri, 25 Jan 2002 19:22:06 GMT; Max-age=3600;
Path=/api/; Domain=.example.com; SameSite=Strict; Partitioned; Secure; HttpOnly"
“‘

### Sanity Check

If one of the following conditions is true, an error is emitted:
- Is ‘name‘ not supplied?
- If ‘secure‘ is not present:
- is ‘samesite=none‘?
- is ‘partitioned‘ present?

“‘common-lisp
(make-cookie :value "asdg")
;; => Invalid Cookie values: No name supplied.
;; You should set at least a dummy name to avoid bugs.
;; [Condition of type INVALID-COOKIE]
“‘
“‘common-lisp
(make-cookie :name "haalllo" :value "asdg" :same-site "None")
;; => Invalid Cookie values: Samesite=None cookies require Secure.
;; [Condition of type INVALID-COOKIE]
“‘
“‘common-lisp
(make-cookie :name "haalllo" :partitioned t)
;; => Invalid Cookie values: Partitioned cookies require Secure.
;; [Condition of type INVALID-COOKIE]
“‘

If you want to deactivate sanity checks (e.g. for performance reasons)
you can either supply parameter ‘sanity-check‘ with ‘nil‘, or set
‘*sanity-check*‘ to ‘nil‘.

“‘common-lisp
(make-cookie :name "haalllo" :partitioned t :sanity-check nil)
;; => #S(COOKIE :NAME "haalllo" :PARTITIONED T
:CREATION-TIMESTAMP 3928172572)
“‘
“‘common-lisp
(let ((cl-cookie:*sanity-check*))
(make-cookie :name "haalllo" :value "asdg" :same-site "None"))
;; => #S(COOKIE :NAME "haalllo" :VALUE "asdg" :SAME-SITE "None"
;; :CREATION-TIMESTAMP 3928172645)
“‘

### cookie struct accessor functions

“‘common-lisp
(cl-cookie:cookie-name *cookie*)
;=> "SID"

(cl-cookie:cookie-value *cookie*)
;=> "31d4d96e407aad42"

(cl-cookie:cookie-expires *cookie*)
;=> 3220975326

(cl-cookie:cookie-path *cookie*)
;=> "/api/"

(cl-cookie:cookie-origin-host *cookie*)
;=> "example.com"
;; host takes precedence over domain, if both are supplied and conflicting.

(cl-cookie:cookie-domain *cookie*)
;=> ".example.com"
;; This cookie is accessible for example.com and all subdomains (e.g. docs.example.com)

(cl-cookie:cookie-same-site *cookie*)
;=> "Strict"

(cl-cookie:cookie-max-age *cookie*)
;=> 3600

(cl-cookie:cookie-partitioned *cookie*)
;=> T

(cl-cookie:cookie-secure-p *cookie*)
;=> T

(cl-cookie:cookie-httponly-p *cookie*)
;=> T
“‘

### parse-set-cookie-header (set-cookie-string origin-host origin-path)

“‘common-lisp
(cl-cookie:parse-set-cookie-header
"my_cookie=my_value; Domain=.example.com; Expires=Sat, 31 Dec 2024 23:59:59 GMT; HttpOnly; Max-Age=7200; Secure; SameSite=None"
"example.com"
"/")
;=> #S(COOKIE :NAME "my_cookie" :VALUE "my_value" :EXPIRES 3944678399 :PATH "/" :DOMAIN ".example.com"
; :SAME-SITE "None" :MAX-AGE 7200 :PARTITIONED NIL :SECURE-P T
; :HTTPONLY-P T :ORIGIN-HOST "example.com" :CREATION-TIMESTAMP 3921467559)
“‘

### make-cookie-jar (&key cookies)
“‘common-lisp
(defparameter *cookie-jar*
(cl-cookie:make-cookie-jar
:cookies (list (cl-cookie:make-cookie
:name "SID"
:value "31d4d96e407aad42"
:origin-host "example.com"
:path "/api/"
:domain ".example.com"
:max-age 3600))))
;=> *cookie-jar*
“‘

### merge-cookies (cookie-jar cookies)
“‘common-lisp
(cl-cookie:merge-cookies
*cookie-jar*
(list (cl-cookie:parse-set-cookie-header
"SID=31d4d96e407aad42; Path=/; Domain=example.com; Partitioned"
"www.example.org"
"/")))
;=> (#S(CL-COOKIE:COOKIE :NAME "SID" :VALUE "31d4d96e407aad42" :PATH "/api/" :DOMAIN ".example.com"
; :ORIGIN-HOST "example.com" :EXPIRES NIL :MAX-AGE 3600 :SAME-SITE NIL
; :PARTITIONED NIL :SECURE-P NIL :HTTPONLY-P NIL :CREATION-TIMESTAMP 3921572023)
; #S(CL-COOKIE:COOKIE :NAME "SID" :VALUE "31d4d96e407aad42" :PATH "/" :DOMAIN "example.com"
; :ORIGIN-HOST "www.example.org" :EXPIRES NIL :MAX-AGE NIL :SAME-SITE NIL
; :PARTITIONED T :SECURE-P NIL :HTTPONLY-P NIL :CREATION-TIMESTAMP 3921572029))
“‘

### cookie-jar-host-cookies (cookie-jar host path &key securep)
“‘common-lisp
(cl-cookie:cookie-jar-host-cookies *cookie-jar*
"example.com"
"/")
;=> (#S(CL-COOKIE:COOKIE :NAME "SID" :VALUE "31d4d96e407aad42" :PATH "/" :DOMAIN "example.com"
; :ORIGIN-HOST "www.example.org" :EXPIRES NIL :MAX-AGE NIL :SAME-SITE NIL
; :PARTITIONED NIL :SECURE-P NIL :HTTPONLY-P NIL :CREATION-TIMESTAMP 3921566005))
“‘

## See also

- [RFC 6265](http://tools.ietf.org/html/rfc6265)
- [Set-Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)

## Author

* Eitaro Fukamachi (e.arrows@gmail.com)

## Copyright

Copyright (c) 2015 Eitaro Fukamachi (e.arrows@gmail.com)

## License

Licensed under the BSD 2-Clause License.

Version

0.1

Dependencies
  • proc-parse (system).
  • cl-ppcre (system).
  • quri (system).
  • local-time (system).
  • alexandria (system).
Source

cl-cookie.asd.

Child Component

src/cl-cookie.lisp (file).


3 Files

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


3.1 Lisp


3.1.1 cl-cookie/cl-cookie.asd

Source

cl-cookie.asd.

Parent Component

cl-cookie (system).

ASDF Systems

cl-cookie.

Packages

cl-cookie-asd.


3.1.2 cl-cookie/src/cl-cookie.lisp

Source

cl-cookie.asd.

Parent Component

cl-cookie (system).

Packages

cl-cookie.

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 cl-cookie-asd

Source

cl-cookie.asd.

Use List
  • asdf/interface.
  • common-lisp.

4.2 cl-cookie

Source

src/cl-cookie.lisp.

Nickname

cookie

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: *sanity-check*
Package

cl-cookie.

Source

src/cl-cookie.lisp.


5.1.2 Ordinary functions

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

domain.

Equality check as in cookie= plus also secure-p, same-site, partitioned, as well as httponly-p.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

expires.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

httponly-p.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

cookies.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

max-age.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

name.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

origin-host.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

partitioned.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

path.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

same-site.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

secure-p.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

value.

Equality check for the attributes name, domain, host and path.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: make-cookie (&rest args &key name value path domain origin-host expires max-age same-site partitioned secure-p httponly-p sanity-check)

Cookie constructor. Convert

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: make-cookie-jar (&key cookies)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: merge-cookies (cookie-jar cookies)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: parse-set-cookie-header (set-cookie-string origin-host origin-path &key sanity-check)

Parse cookie header string and return a cookie struct instance populated with the respective slots.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: write-cookie-header (cookies &optional stream)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: write-set-cookie-header (cookie &optional stream)

Writes full header in conformance with RFC 6265 plus some additional attributes.

Package

cl-cookie.

Source

src/cl-cookie.lisp.


5.1.3 Conditions

Condition: invalid-cookie
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Direct superclasses

error.

Direct slots
Slot: header
Initargs

:header


5.1.4 Structures

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Direct superclasses

structure-object.

Direct slots
Slot: name
Type

(or null string)

Readers

cookie-name.

Writers

(setf cookie-name).

Slot: value
Type

(or null string)

Readers

cookie-value.

Writers

(setf cookie-value).

Slot: path
Type

(or null string)

Readers

cookie-path.

Writers

(setf cookie-path).

Slot: domain
Type

(or null string)

Readers

cookie-domain.

Writers

(setf cookie-domain).

Slot: origin-host
Type

(or null string)

Readers

cookie-origin-host.

Writers

(setf cookie-origin-host).

Slot: expires
Type

(or null integer)

Readers

cookie-expires.

Writers

(setf cookie-expires).

Slot: max-age
Type

(or null integer)

Readers

cookie-max-age.

Writers

(setf cookie-max-age).

Slot: same-site
Type

(or null cl-cookie::same-site)

Readers

cookie-same-site.

Writers

(setf cookie-same-site).

Slot: partitioned
Type

boolean

Readers

cookie-partitioned.

Writers

(setf cookie-partitioned).

Slot: secure-p
Type

boolean

Readers

cookie-secure-p.

Writers

(setf cookie-secure-p).

Slot: httponly-p
Type

boolean

Readers

cookie-httponly-p.

Writers

(setf cookie-httponly-p).

Slot: creation-timestamp
Type

integer

Initform

(get-universal-time)

Readers

cookie-creation-timestamp.

Writers

This slot is read-only.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Direct superclasses

structure-object.

Direct slots
Slot: cookies
Readers

cookie-jar-cookies.

Writers

(setf cookie-jar-cookies).


5.2 Internals


5.2.1 Special variables

Special Variable: *current-century-offset*
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Special Variable: +set-cookie-date-format+

The date format used in RFC 6265. For example: Wed, 09 Jun 2021 10:18:14 GMT.

Package

cl-cookie.

Source

src/cl-cookie.lisp.


5.2.2 Ordinary functions

Function: %make-cookie (&key name value path domain origin-host expires max-age same-site partitioned secure-p httponly-p creation-timestamp)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Target Slot

creation-timestamp.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: copy-cookie (instance)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: copy-cookie-jar (instance)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: delete-old-cookies (cookie-jar)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: expired-cookie-p (cookie)

Check if cookie is expired, whereas max-age has priority over expires.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: get-tz-offset (tz-abbrev)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: integer-char-p (char)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: match-cookie (cookie host path &key securep)

Get all available cookies for a specific host and path.

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: match-cookie-path (request-path cookie-path)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: parse-cookie-date (cookie-date)
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: same-site-p (same-site)

Predicate for allowed values of same-site attribute

Package

cl-cookie.

Source

src/cl-cookie.lisp.

Function: sanity-check (cookie)

If one of the following condition is true, an error is emitted: - Is name not supplied?
- If secure is not present:
- is samesite=none?
- is partitioned present?

Package

cl-cookie.

Source

src/cl-cookie.lisp.


5.2.3 Conditions

Condition: invalid-expires-date
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Direct superclasses

error.

Direct slots
Slot: expires
Initargs

:expires

Condition: invalid-set-cookie
Package

cl-cookie.

Source

src/cl-cookie.lisp.

Direct superclasses

error.

Direct slots
Slot: header
Initargs

:header


5.2.4 Types

Type: same-site ()
Package

cl-cookie.

Source

src/cl-cookie.lisp.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   %   (  
C   D   E   F   G   I   M   P   S   W  
Index Entry  Section

%
%make-cookie: Private ordinary functions

(
(setf cookie-domain): Public ordinary functions
(setf cookie-expires): Public ordinary functions
(setf cookie-httponly-p): Public ordinary functions
(setf cookie-jar-cookies): Public ordinary functions
(setf cookie-max-age): Public ordinary functions
(setf cookie-name): Public ordinary functions
(setf cookie-origin-host): Public ordinary functions
(setf cookie-partitioned): Public ordinary functions
(setf cookie-path): Public ordinary functions
(setf cookie-same-site): Public ordinary functions
(setf cookie-secure-p): Public ordinary functions
(setf cookie-value): Public ordinary functions

C
cookie-creation-timestamp: Private ordinary functions
cookie-domain: Public ordinary functions
cookie-equal: Public ordinary functions
cookie-expires: Public ordinary functions
cookie-httponly-p: Public ordinary functions
cookie-jar-cookies: Public ordinary functions
cookie-jar-host-cookies: Public ordinary functions
cookie-jar-p: Private ordinary functions
cookie-max-age: Public ordinary functions
cookie-name: Public ordinary functions
cookie-origin-host: Public ordinary functions
cookie-p: Private ordinary functions
cookie-partitioned: Public ordinary functions
cookie-path: Public ordinary functions
cookie-same-site: Public ordinary functions
cookie-secure-p: Public ordinary functions
cookie-value: Public ordinary functions
cookie=: Public ordinary functions
copy-cookie: Private ordinary functions
copy-cookie-jar: Private ordinary functions

D
delete-old-cookies: Private ordinary functions

E
expired-cookie-p: Private ordinary functions

F
Function, %make-cookie: Private ordinary functions
Function, (setf cookie-domain): Public ordinary functions
Function, (setf cookie-expires): Public ordinary functions
Function, (setf cookie-httponly-p): Public ordinary functions
Function, (setf cookie-jar-cookies): Public ordinary functions
Function, (setf cookie-max-age): Public ordinary functions
Function, (setf cookie-name): Public ordinary functions
Function, (setf cookie-origin-host): Public ordinary functions
Function, (setf cookie-partitioned): Public ordinary functions
Function, (setf cookie-path): Public ordinary functions
Function, (setf cookie-same-site): Public ordinary functions
Function, (setf cookie-secure-p): Public ordinary functions
Function, (setf cookie-value): Public ordinary functions
Function, cookie-creation-timestamp: Private ordinary functions
Function, cookie-domain: Public ordinary functions
Function, cookie-equal: Public ordinary functions
Function, cookie-expires: Public ordinary functions
Function, cookie-httponly-p: Public ordinary functions
Function, cookie-jar-cookies: Public ordinary functions
Function, cookie-jar-host-cookies: Public ordinary functions
Function, cookie-jar-p: Private ordinary functions
Function, cookie-max-age: Public ordinary functions
Function, cookie-name: Public ordinary functions
Function, cookie-origin-host: Public ordinary functions
Function, cookie-p: Private ordinary functions
Function, cookie-partitioned: Public ordinary functions
Function, cookie-path: Public ordinary functions
Function, cookie-same-site: Public ordinary functions
Function, cookie-secure-p: Public ordinary functions
Function, cookie-value: Public ordinary functions
Function, cookie=: Public ordinary functions
Function, copy-cookie: Private ordinary functions
Function, copy-cookie-jar: Private ordinary functions
Function, delete-old-cookies: Private ordinary functions
Function, expired-cookie-p: Private ordinary functions
Function, get-tz-offset: Private ordinary functions
Function, integer-char-p: Private ordinary functions
Function, make-cookie: Public ordinary functions
Function, make-cookie-jar: Public ordinary functions
Function, match-cookie: Private ordinary functions
Function, match-cookie-path: Private ordinary functions
Function, merge-cookies: Public ordinary functions
Function, parse-cookie-date: Private ordinary functions
Function, parse-set-cookie-header: Public ordinary functions
Function, same-site-p: Private ordinary functions
Function, sanity-check: Private ordinary functions
Function, write-cookie-header: Public ordinary functions
Function, write-set-cookie-header: Public ordinary functions

G
get-tz-offset: Private ordinary functions

I
integer-char-p: Private ordinary functions

M
make-cookie: Public ordinary functions
make-cookie-jar: Public ordinary functions
match-cookie: Private ordinary functions
match-cookie-path: Private ordinary functions
merge-cookies: Public ordinary functions

P
parse-cookie-date: Private ordinary functions
parse-set-cookie-header: Public ordinary functions

S
same-site-p: Private ordinary functions
sanity-check: Private ordinary functions

W
write-cookie-header: Public ordinary functions
write-set-cookie-header: Public ordinary functions


A.3 Variables

Jump to:   *   +  
C   D   E   H   M   N   O   P   S   V  
Index Entry  Section

*
*current-century-offset*: Private special variables
*sanity-check*: Public special variables

+
+set-cookie-date-format+: Private special variables

C
cookies: Public structures
creation-timestamp: Public structures

D
domain: Public structures

E
expires: Public structures
expires: Private conditions

H
header: Public conditions
header: Private conditions
httponly-p: Public structures

M
max-age: Public structures

N
name: Public structures

O
origin-host: Public structures

P
partitioned: Public structures
path: Public structures

S
same-site: Public structures
secure-p: Public structures
Slot, cookies: Public structures
Slot, creation-timestamp: Public structures
Slot, domain: Public structures
Slot, expires: Public structures
Slot, expires: Private conditions
Slot, header: Public conditions
Slot, header: Private conditions
Slot, httponly-p: Public structures
Slot, max-age: Public structures
Slot, name: Public structures
Slot, origin-host: Public structures
Slot, partitioned: Public structures
Slot, path: Public structures
Slot, same-site: Public structures
Slot, secure-p: Public structures
Slot, value: Public structures
Special Variable, *current-century-offset*: Private special variables
Special Variable, *sanity-check*: Public special variables
Special Variable, +set-cookie-date-format+: Private special variables

V
value: Public structures