Safe Haskell | None |
---|---|
Language | Haskell2010 |
WebGear.Core.Trait.Cookie
Contents
Description
Traits and middlewares to handle cookies in requests and responses.
Synopsis
- data Cookie (e :: Existence) (name :: Symbol) val = Cookie
- data CookieNotFound = CookieNotFound
- newtype CookieParseError = CookieParseError Text
- data SetCookie (e :: Existence) (name :: Symbol) = SetCookie
- cookie :: forall (name :: Symbol) val h (ts :: [Type]). (ArrowChoice h, Get h (Cookie 'Required name val), HasTrait (RequestHeader 'Required 'Strict "Cookie" Text) ts) => h (With Request ts, Either CookieNotFound CookieParseError) Response -> Middleware h ts (Cookie 'Required name val ': ts)
- optionalCookie :: forall (name :: Symbol) val h (ts :: [Type]). (ArrowChoice h, Get h (Cookie 'Optional name val), HasTrait (RequestHeader 'Optional 'Strict "Cookie" Text) ts) => h (With Request ts, CookieParseError) Response -> Middleware h ts (Cookie 'Optional name val ': ts)
- setCookie :: forall (name :: Symbol) h (ts :: [Type]). Set h (SetCookie 'Required name) => h (With Response ts, SetCookie) (With Response (SetCookie 'Required name ': ts))
- setOptionalCookie :: forall (name :: Symbol) h (ts :: [Type]). Set h (SetCookie 'Optional name) => h (With Response ts, Maybe SetCookie) (With Response (SetCookie 'Optional name ': ts))
Traits
data Cookie (e :: Existence) (name :: Symbol) val Source #
Trait for a cookie in HTTP requests
Constructors
Cookie |
Instances
type Absence (Cookie 'Optional name val) Source # | |
Defined in WebGear.Core.Trait.Cookie | |
type Absence (Cookie 'Required name val) Source # | |
Defined in WebGear.Core.Trait.Cookie | |
type Attribute (Cookie 'Optional name val) Request Source # | |
type Attribute (Cookie 'Required name val) Request Source # | |
Defined in WebGear.Core.Trait.Cookie | |
type Prerequisite (Cookie e name val) ts Source # | |
Defined in WebGear.Core.Trait.Cookie |
data CookieNotFound Source #
Indicates a missing cookie
Constructors
CookieNotFound |
Instances
Read CookieNotFound Source # | |
Defined in WebGear.Core.Trait.Cookie Methods readsPrec :: Int -> ReadS CookieNotFound # readList :: ReadS [CookieNotFound] # | |
Show CookieNotFound Source # | |
Defined in WebGear.Core.Trait.Cookie Methods showsPrec :: Int -> CookieNotFound -> ShowS # show :: CookieNotFound -> String # showList :: [CookieNotFound] -> ShowS # | |
Eq CookieNotFound Source # | |
Defined in WebGear.Core.Trait.Cookie Methods (==) :: CookieNotFound -> CookieNotFound -> Bool # (/=) :: CookieNotFound -> CookieNotFound -> Bool # |
newtype CookieParseError Source #
Error in converting a cookie to the expected type
Constructors
CookieParseError Text |
Instances
Read CookieParseError Source # | |
Defined in WebGear.Core.Trait.Cookie Methods readsPrec :: Int -> ReadS CookieParseError # readList :: ReadS [CookieParseError] # | |
Show CookieParseError Source # | |
Defined in WebGear.Core.Trait.Cookie Methods showsPrec :: Int -> CookieParseError -> ShowS # show :: CookieParseError -> String # showList :: [CookieParseError] -> ShowS # | |
Eq CookieParseError Source # | |
Defined in WebGear.Core.Trait.Cookie Methods (==) :: CookieParseError -> CookieParseError -> Bool # (/=) :: CookieParseError -> CookieParseError -> Bool # |
data SetCookie (e :: Existence) (name :: Symbol) Source #
Trait for a cookie in HTTP responses
Constructors
SetCookie |
Middlewares
Arguments
:: forall (name :: Symbol) val h (ts :: [Type]). (ArrowChoice h, Get h (Cookie 'Required name val), HasTrait (RequestHeader 'Required 'Strict "Cookie" Text) ts) | |
=> h (With Request ts, Either CookieNotFound CookieParseError) Response | Error handler |
-> Middleware h ts (Cookie 'Required name val ': ts) |
Extract a cookie and convert it to a value of type val
.
The associated trait attribute has type val
.
Example usage:
cookie @"name" @Integer errorHandler okHandler
Arguments
:: forall (name :: Symbol) val h (ts :: [Type]). (ArrowChoice h, Get h (Cookie 'Optional name val), HasTrait (RequestHeader 'Optional 'Strict "Cookie" Text) ts) | |
=> h (With Request ts, CookieParseError) Response | Error handler |
-> Middleware h ts (Cookie 'Optional name val ': ts) |
Extract an optional cookie and convert it to a value of type val
.
The associated trait attribute has type Maybe val
; a Nothing
value indicates that the cookie is missing from the request.
Example usage:
optionalCookie @"name" @Integer errorHandler okHandler
setCookie :: forall (name :: Symbol) h (ts :: [Type]). Set h (SetCookie 'Required name) => h (With Response ts, SetCookie) (With Response (SetCookie 'Required name ': ts)) Source #
Set a cookie value in a response.
Example usage:
response' <- setCookie @"name" -< (response, cookie)
setOptionalCookie :: forall (name :: Symbol) h (ts :: [Type]). Set h (SetCookie 'Optional name) => h (With Response ts, Maybe SetCookie) (With Response (SetCookie 'Optional name ': ts)) Source #
Set an optional cookie value in a response.
Setting the cookie to Nothing
will remove it from the response if
it was previously set. The cookie will be considered as optional in
all relevant places (such as documentation).
Example usage:
response' <- setOptionalCookie @"name" -< (response, cookie)