-2

Here is how I am sending a get request:

import Network.HTTP.Conduit
import Control.Applicative ((<$>))
import Network.HTTP.Types

request <- parseUrl $ "someUrl"
res <- withManager $ httpLbs request
putStrLn $ show $ responseCookieJar res

Instead of printing responseCookieJar I want to get a value from it. This http://hackage.haskell.org/package/http-conduit-2.1.2/docs/Network-HTTP-Conduit.html#t:CookieJar implies that it's not possible. So I figure I have to parse (by regexp) it as a string. But there must a standard way like getting a value by its key.

Isn't there?

Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
Incerteza
  • 32,326
  • 47
  • 154
  • 261
  • I've rolled back the update as it's a completely different question and the answer doesn't really fit with the answer to the existing question. (It's a pretty basic problem with precedence, so just try putting in more brackets before actually asking the question) – Ganesh Sittampalam Jul 06 '14 at 12:57
  • 1
    Please put your new question in a new question. Thanks. – AndrewC Jul 06 '14 at 18:28
  • Please don't keep moving the goalposts for people who answer your questions. – Flexo Jul 06 '14 at 23:29

2 Answers2

3

You can use destroyCookieJar to turn it into a list of Cookies, which you can then inspect via various field accessors.

The two most useful for keys are probably cookie_name and cookie_path. So you might do something like

filter (\c -> cookie_name c == pack "foo") . destroyCookieJar

(using pack from Data.Bytestring.Char8)

Or if there are a lot of cookies and you want to do multiple queries, you may want to build something like a Map from name to cookie first.

Ganesh Sittampalam
  • 28,821
  • 4
  • 79
  • 98
3

You can call destroyCookieJar to break it into the individual Cookies, and then search that list.

huon
  • 94,605
  • 21
  • 231
  • 225