Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Traits and middlewares to handle cookies in requests and responses.
Synopsis
- data Cookie (e :: Existence) (name :: Symbol) (val :: Type) = Cookie
- data CookieNotFound = CookieNotFound
- newtype CookieParseError = CookieParseError Text
- data SetCookie (e :: Existence) (name :: Symbol) = SetCookie
- cookie :: forall name val h ts. (ArrowChoice h, Get h (Cookie Required name val) Request, HasTrait (RequestHeader Required Strict "Cookie" Text) ts) => h (Request `With` ts, Either CookieNotFound CookieParseError) Response -> Middleware h ts (Cookie Required name val : ts)
- optionalCookie :: forall name val h ts. (ArrowChoice h, Get h (Cookie Optional name val) Request, HasTrait (RequestHeader Optional Strict "Cookie" Text) ts) => h (Request `With` ts, CookieParseError) Response -> Middleware h ts (Cookie Optional name val : ts)
- setCookie :: forall name h ts. Set h (SetCookie Required name) Response => h (Response `With` ts, SetCookie) (Response `With` (SetCookie Required name : ts))
- setOptionalCookie :: forall name h ts. Set h (SetCookie Optional name) Response => h (Response `With` ts, Maybe SetCookie) (Response `With` (SetCookie Optional name : ts))
Traits
data Cookie (e :: Existence) (name :: Symbol) (val :: Type) Source #
Trait for a cookie in HTTP requests
Instances
Trait (Cookie 'Optional name val) Request Source # | |
Trait (Cookie 'Required name val) Request Source # | |
TraitAbsence (Cookie 'Optional name val) Request Source # | |
TraitAbsence (Cookie 'Required name val) Request Source # | |
type Absence (Cookie 'Optional name val) Request Source # | |
Defined in WebGear.Core.Trait.Cookie | |
type Absence (Cookie 'Required name val) Request 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 Request Source # | |
Defined in WebGear.Core.Trait.Cookie type Prerequisite (Cookie e name val) ts Request = HasTrait (RequestHeader e 'Strict "Cookie" Text) ts |
data CookieNotFound Source #
Indicates a missing cookie
Instances
Read CookieNotFound Source # | |
Defined in WebGear.Core.Trait.Cookie readsPrec :: Int -> ReadS CookieNotFound # readList :: ReadS [CookieNotFound] # | |
Show CookieNotFound Source # | |
Defined in WebGear.Core.Trait.Cookie showsPrec :: Int -> CookieNotFound -> ShowS # show :: CookieNotFound -> String # showList :: [CookieNotFound] -> ShowS # | |
Eq CookieNotFound Source # | |
Defined in WebGear.Core.Trait.Cookie (==) :: CookieNotFound -> CookieNotFound -> Bool # (/=) :: CookieNotFound -> CookieNotFound -> Bool # |
newtype CookieParseError Source #
Error in converting a cookie to the expected type
Instances
Read CookieParseError Source # | |
Defined in WebGear.Core.Trait.Cookie | |
Show CookieParseError Source # | |
Defined in WebGear.Core.Trait.Cookie showsPrec :: Int -> CookieParseError -> ShowS # show :: CookieParseError -> String # showList :: [CookieParseError] -> ShowS # | |
Eq CookieParseError Source # | |
Defined in WebGear.Core.Trait.Cookie (==) :: CookieParseError -> CookieParseError -> Bool # (/=) :: CookieParseError -> CookieParseError -> Bool # |
data SetCookie (e :: Existence) (name :: Symbol) Source #
Trait for a cookie in HTTP responses
Middlewares
:: forall name val h ts. (ArrowChoice h, Get h (Cookie Required name val) Request, HasTrait (RequestHeader Required Strict "Cookie" Text) ts) | |
=> h (Request `With` 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
:: forall name val h ts. (ArrowChoice h, Get h (Cookie Optional name val) Request, HasTrait (RequestHeader Optional Strict "Cookie" Text) ts) | |
=> h (Request `With` 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 h ts. Set h (SetCookie Required name) Response => h (Response `With` ts, SetCookie) (Response `With` (SetCookie Required name : ts)) Source #
Set a cookie value in a response.
Example usage:
response' <- setCookie @"name" -< (response, cookie)
setOptionalCookie :: forall name h ts. Set h (SetCookie Optional name) Response => h (Response `With` ts, Maybe SetCookie) (Response `With` (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)