Module

Biscotti.Cookie

This module allows parsing and generating cookie headers. You'll generally use the Cookie.new function to create a cookie from a name/value pair and the Cookie.set* functions to set attributes on a cookie.

Cookie.stringify generates the string representation of a cookie, suitable for writing to an HTTP header.

Cookie.parse parses the string representation of a cookie, returning an Either ParseError Cookie.

import Biscotti.Cookie as Cookie

> Cookie.stringify $ Cookie.setSecure $ Cookie.new "key" "value"
key=value; Secure

> Cookie.parse "key=value; Secure"
(Right { name: "key", value: "value", secure: true, ... })

Re-exports from Biscotti.Cookie.Generator

#stringify

stringify :: Cookie -> String

Return the String representation of a Cookie.

> Generator.stringify $ Cookie.setSecure $ Cookie.new "key" "value"
key=value; Secure

Re-exports from Biscotti.Cookie.Parser

#parseMany

parseMany :: String -> Either ParseError (List Cookie)

Parses a String into an Either ParseError (List Cookie). HTTP requests can include multiple cookies in a single Cookie header consisting of only name/value pairs. This function can be used to parse this header.

> parseMany "key1=value1; key2=value2"
(Right ({ name: "key1", value: "value1", ... } : { name: "key2", value: "value2", ... } : Nil))

#parse

parse :: String -> Either ParseError Cookie

Parses a String into an Either ParseError Cookie. This function is primarily intended to parse the Set-Cookie header on the client.

> Parser.parse "key=value; Secure"
(Right { name: "key", value: "value", secure: true, ... })

Re-exports from Biscotti.Cookie.Types

#SameSite

data SameSite

Type representing a Cookie's optional SameSite attribute.

Constructors

Instances

#Cookie

newtype Cookie

The Cookie type

Instances

#setSecure

#setSameSite

#setPath

#setMaxAge

#setHttpOnly

#setExpires

#setDomain

#new

new :: String -> String -> Cookie

The constructor for Cookie

#getValue

#getSecure

#getPath

#getName

#getMaxAge

#getHttpOnly

#getExpires

#getDomain

#expire

expire :: Cookie -> Effect (Either String Cookie)

Expire an existing Cookie. This sets the Expires attribute of the cookie to yesterday's date.

Modules