From b650ab321c6ef234723aea02ab3fb58caeec72fb Mon Sep 17 00:00:00 2001 From: Henrik Feldt Date: Tue, 13 Oct 2015 19:38:52 +0200 Subject: [PATCH] [cookies] fixes #309 The reason for this bug, is because we just changed the semantics of setHeader to overwrite any existing identical header and the cookie behaviour was depending on the addative behaviour --- examples/Example/Program.fs | 9 +++++++-- src/Suave/Cookie.fs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/Example/Program.fs b/examples/Example/Program.fs index 350d8498..454af59b 100755 --- a/examples/Example/Program.fs +++ b/examples/Example/Program.fs @@ -98,8 +98,13 @@ let app = path "/session" >>= statefulForSession // Session.State.CookieStateStore >>= context (fun x -> - match x |> HttpContext.state with - | None -> Redirection.FOUND "/session" // restarted server without keeping the key; set key manually? + match HttpContext.state x with + | None -> + // restarted server without keeping the key; set key manually? + let msg = "Server Key, Cookie Serialiser reset, or Cookie Data Corrupt, " + + "if you refresh the browser page, you'll have gotten a new cookie." + OK msg + | Some store -> match store.get "counter" with | Some y -> diff --git a/src/Suave/Cookie.fs b/src/Suave/Cookie.fs index ed874142..776eba04 100644 --- a/src/Suave/Cookie.fs +++ b/src/Suave/Cookie.fs @@ -114,7 +114,7 @@ module Cookie = let unsetCookie (cookieName : string) = let startEpoch = DateTimeOffset(1970, 1, 1, 0, 0, 1, TimeSpan.Zero) |> Some let stringValue = HttpCookie.toHeader { HttpCookie.mkKV cookieName "x" with expires = startEpoch } - Writers.setHeader "Set-Cookie" stringValue + Writers.addHeader "Set-Cookie" stringValue let setPair (httpCookie : HttpCookie) (clientCookie : HttpCookie) : WebPart = context (fun { runtime = { logger = logger } } ->