Skip to content

Commit

Permalink
Include cookies in rspHeaders, in addition to rspCookies
Browse files Browse the repository at this point in the history
(flip (++)) was chosen under the assumption that there will usually
be more cookies in rspCookies than in rspHeaders
  • Loading branch information
lpsmith committed Jan 31, 2011
1 parent cd3dc3e commit f417f4e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Snap/Internal/Http/Server.hs
Expand Up @@ -776,7 +776,7 @@ sendResponse req rsp' buffer writeEnd' onSendFile = do
where where
f h = if null cookies f h = if null cookies
then h then h
else Map.insert "Set-Cookie" cookies h else Map.insertWith (flip (++)) "Set-Cookie" cookies h
cookies = fmap cookieToBS . Map.elems $ rspCookies r cookies = fmap cookieToBS . Map.elems $ rspCookies r




Expand Down

2 comments on commit f417f4e

@snapframework
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is OK w/ me (and I will pull it later) but I would prefer it if the stuff you're trying to do was included in our Cookie object also.

@lpsmith
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I never added it to the Cookie record, I just did this:

addHttpCookie :: Cookie            -- ^ cookie value
              -> Response          -- ^ response to modify
              -> Response
addHttpCookie (Cookie k v mbExpTime mbDomain mbPath) = updateHeaders f
  where
    f       = Map.insertWith' (++) "Set-Cookie" [cookie]
    cookie  = Char8.concat [k, "=", v, path, exptime, domain, "; httponly"]
    path    = maybe "" (Char8.append "; path=") mbPath
    domain  = maybe "" (Char8.append "; domain=") mbDomain
    exptime = maybe "" (Char8.append "; expires=" . fmt) mbExpTime
    fmt = Char8.pack . formatTime defaultTimeLocale "%a, %d-%b-%Y %H:%M:%S GMT"

Which is identical to the older addCookie, except for the "; httponly" bit. And, there are other things we don't support, such as expiring 8 hours in the future, instead of at 6:24 pm (UTC), which should arguably be supported as well, but at least this gives people a workaround if there is some obscure cookie thing we don't support.

Please sign in to comment.