[web-devel] Add session header to response of Wai.Application.Static.staticApp

Leif Warner abimelech at gmail.com
Mon Feb 17 08:40:56 UTC 2014


Ah, shoulda checked here first, sorry - there's a "mapHeaders" method in
wai-util:
https://github.com/singpolyma/wai-util/blob/master/Network/Wai/Util.hs#L90


On Mon, Feb 17, 2014 at 12:37 AM, Leif Warner <abimelech at gmail.com> wrote:

> I want to add a session cookie header to the response of staticApp.
>
> Now, I know that adding a "session" to a static file doesn't make sense.
> I just figured I'd set the session once on the splash page, rather than
> risk generating multiple sessions for the subsequently fetched "dynamic"
> resources. (They're actually static files, but per-user copies of the
> static files.)
>
> I was maybe hoping for something along the lines of:
> do
>   response <- (staticApp $ defaultWebAppSettings ".") request
>   return $ response { responseHeaders = sessionCookie : responseHeaders
> response }
>
> But that will tell me "`responseHeaders' is not a record selector".
>
> staticApp returns either ResponseFile, or ResponseBuilder (304 "Not
> Modified").  I could import Network.Wai.Internal, pattern match on those,
> and return those w/ the added header.
>
> That seems a bit crufty, though - was hoping someone could suggest a more
> elegant solution?
>
> Maybe some Lens or Functor instance across a response's headers, I dunno.
>
> -Leif
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20140217/a825e610/attachment.html>


More information about the web-devel mailing list