[web-devel] Getting the http request header in Yesod?
Michael Snoyman
michael at snoyman.com
Sat Sep 25 18:57:40 CEST 2010
On Sat, Sep 25, 2010 at 10:32 AM, Rehno Lindeque <errantkid at gmail.com> wrote:
> I'm looking to detect ajax requests sent to my yesod application using
> the technique detailed in http://davidwalsh.name/detect-ajax
>
> Is it possible to gain access to the request header directly or would
> yesod require modification to get at it? If someone could just point
> me in the right direction, I would be grateful. I imagine it would be
> a function returning GHandler?
You can use waiRequest[1] to get access to the WAI request value, and
requestHeaders[2] to get the request headers from it. It's very
convenient to use the OverloadedStrings extensions when dealing with
the CIByteString datatype[3].
Hope that helps,
Michael
[1] http://hackage.haskell.org/packages/archive/yesod/0.5.0.3/doc/html/Yesod-Request.html#v:waiRequest
[2] http://hackage.haskell.org/packages/archive/wai/0.2.0/doc/html/Network-Wai.html#v:requestHeaders
[3] http://hackage.haskell.org/packages/archive/wai/0.2.0/doc/html/Network-Wai.html#t:CIByteString
More information about the web-devel
mailing list