mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-23 03:42:04 +03:00
Rename function.
This commit is contained in:
parent
1fe11c9253
commit
1609f487ff
@ -13,7 +13,7 @@ import Server.SetCookie as SetCookie
|
||||
|
||||
cookieOptions : SetCookie.Options
|
||||
cookieOptions =
|
||||
SetCookie.initOptions
|
||||
SetCookie.options
|
||||
|> SetCookie.withPath "/"
|
||||
|> SetCookie.withSameSite SetCookie.Lax
|
||||
|
||||
|
@ -318,7 +318,7 @@ encodeSessionUpdate config toRequest userRequestData sessionResult =
|
||||
(\encoded ->
|
||||
response
|
||||
|> Server.Response.withSetCookieHeader
|
||||
(SetCookie.setCookie config.name encoded (config.options |> Maybe.withDefault SetCookie.initOptions))
|
||||
(SetCookie.setCookie config.name encoded (config.options |> Maybe.withDefault SetCookie.options))
|
||||
)
|
||||
(sign config.secrets
|
||||
(encodeNonExpiringPairs sessionUpdate)
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Server.SetCookie exposing
|
||||
( SetCookie
|
||||
, SameSite(..)
|
||||
, Options, initOptions
|
||||
, Options, options
|
||||
, withImmediateExpiration, makeVisibleToJavaScript, nonSecure, setCookie, withDomain, withExpiration, withMaxAge, withPath, withoutPath, withSameSite
|
||||
, toString
|
||||
)
|
||||
@ -27,7 +27,7 @@ You can learn more about the basics of cookies in the Web Platform in these help
|
||||
|
||||
## Options
|
||||
|
||||
@docs Options, initOptions
|
||||
@docs Options, options
|
||||
|
||||
@docs withImmediateExpiration, makeVisibleToJavaScript, nonSecure, setCookie, withDomain, withExpiration, withMaxAge, withPath, withoutPath, withSameSite
|
||||
|
||||
@ -95,24 +95,24 @@ toString builder =
|
||||
else
|
||||
""
|
||||
|
||||
options : Options
|
||||
options =
|
||||
options_ : Options
|
||||
options_ =
|
||||
builder.options
|
||||
|
||||
httpOnly : Bool
|
||||
httpOnly =
|
||||
not options.visibleToJavaScript
|
||||
not options_.visibleToJavaScript
|
||||
in
|
||||
builder.name
|
||||
++ "="
|
||||
++ Url.percentEncode builder.value
|
||||
++ option "Expires" (options.expiration |> Maybe.map Utc.fromTime)
|
||||
++ option "Max-Age" (options.maxAge |> Maybe.map String.fromInt)
|
||||
++ option "Path" options.path
|
||||
++ option "Domain" options.domain
|
||||
++ option "SameSite" (options.sameSite |> Maybe.map sameSiteToString)
|
||||
++ option "Expires" (options_.expiration |> Maybe.map Utc.fromTime)
|
||||
++ option "Max-Age" (options_.maxAge |> Maybe.map String.fromInt)
|
||||
++ option "Path" options_.path
|
||||
++ option "Domain" options_.domain
|
||||
++ option "SameSite" (options_.sameSite |> Maybe.map sameSiteToString)
|
||||
++ boolOption "HttpOnly" httpOnly
|
||||
++ boolOption "Secure" options.secure
|
||||
++ boolOption "Secure" options_.secure
|
||||
|
||||
|
||||
sameSiteToString : SameSite -> String
|
||||
@ -130,16 +130,17 @@ sameSiteToString sameSite =
|
||||
|
||||
{-| -}
|
||||
setCookie : String -> String -> Options -> SetCookie
|
||||
setCookie name value options =
|
||||
setCookie name value options_ =
|
||||
{ name = name
|
||||
, value = value
|
||||
, options = options
|
||||
, options = options_
|
||||
}
|
||||
|
||||
|
||||
{-| -}
|
||||
initOptions : Options
|
||||
initOptions =
|
||||
{-| Initialize the default `SetCookie` `Options`. Can be configured directly through a record update, or with `withExpiration`, etc.
|
||||
-}
|
||||
options : Options
|
||||
options =
|
||||
{ expiration = Nothing
|
||||
, visibleToJavaScript = False
|
||||
, maxAge = Nothing
|
||||
|
@ -12,7 +12,7 @@ all =
|
||||
describe "SetCookie"
|
||||
[ test "simple value" <|
|
||||
\() ->
|
||||
initOptions
|
||||
options
|
||||
|> nonSecure
|
||||
|> withoutPath
|
||||
|> makeVisibleToJavaScript
|
||||
@ -21,7 +21,7 @@ all =
|
||||
|> Expect.equal "sessionId=38afes7a8"
|
||||
, test "with expiration" <|
|
||||
\() ->
|
||||
initOptions
|
||||
options
|
||||
|> nonSecure
|
||||
|> withoutPath
|
||||
|> withExpiration (Time.millisToPosix 1445412480000)
|
||||
@ -31,7 +31,7 @@ all =
|
||||
|> Expect.equal "id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT"
|
||||
, test "http-only, multiple values" <|
|
||||
\() ->
|
||||
initOptions
|
||||
options
|
||||
|> withoutPath
|
||||
|> nonSecure
|
||||
|> withExpiration (Time.millisToPosix 1445412480000)
|
||||
@ -40,7 +40,7 @@ all =
|
||||
|> Expect.equal "id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; HttpOnly"
|
||||
, test "immediate expiration" <|
|
||||
\() ->
|
||||
initOptions
|
||||
options
|
||||
|> nonSecure
|
||||
|> withoutPath
|
||||
|> withImmediateExpiration
|
||||
@ -50,7 +50,7 @@ all =
|
||||
|> Expect.equal "id=a3fWa; Expires=Thu, 01 Jan 1970 00:00:00 GMT"
|
||||
, test "with path" <|
|
||||
\() ->
|
||||
initOptions
|
||||
options
|
||||
|> nonSecure
|
||||
|> withPath "/"
|
||||
|> makeVisibleToJavaScript
|
||||
@ -59,7 +59,7 @@ all =
|
||||
|> Expect.equal "id=a3fWa; Path=/"
|
||||
, test "with max-age" <|
|
||||
\() ->
|
||||
initOptions
|
||||
options
|
||||
|> nonSecure
|
||||
|> withMaxAge 123
|
||||
|> makeVisibleToJavaScript
|
||||
@ -69,7 +69,7 @@ all =
|
||||
|> Expect.equal "id=a3fWa; Max-Age=123"
|
||||
, test "encodes values" <|
|
||||
\() ->
|
||||
initOptions
|
||||
options
|
||||
|> nonSecure
|
||||
|> withoutPath
|
||||
|> makeVisibleToJavaScript
|
||||
@ -78,7 +78,7 @@ all =
|
||||
|> Expect.equal "id=This%20needs%20encoding%20%26%20it%20uses%20url%20encoding"
|
||||
, test "with domain" <|
|
||||
\() ->
|
||||
initOptions
|
||||
options
|
||||
|> nonSecure
|
||||
|> withoutPath
|
||||
|> withDomain "example.com"
|
||||
@ -88,7 +88,7 @@ all =
|
||||
|> Expect.equal "id=a3fWa; Domain=example.com"
|
||||
, test "secure" <|
|
||||
\() ->
|
||||
initOptions
|
||||
options
|
||||
|> makeVisibleToJavaScript
|
||||
|> withoutPath
|
||||
|> setCookie "id" "a3fWa"
|
||||
@ -96,7 +96,7 @@ all =
|
||||
|> Expect.equal "id=a3fWa; Secure"
|
||||
, test "SameSite" <|
|
||||
\() ->
|
||||
initOptions
|
||||
options
|
||||
|> nonSecure
|
||||
|> withSameSite Strict
|
||||
|> withoutPath
|
||||
|
Loading…
Reference in New Issue
Block a user