Add session header to response of Wai.Application.Static.staticApp

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

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
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
participants (1)
-
Leif Warner