Git Product home page Git Product logo

Comments (8)

mrkkrp avatar mrkkrp commented on August 28, 2024

I am unsure what you are asking. Req allows you to use a specific CookieJar and then get it from the response. For all the manipulations you should use the functions from http-client (which I believe are pure). Would you like Req to provide a more declarative API for cookie manipulation?

In any other language (even F#) I could do this from scratch (with zero previous knowledge) maybe for 20 minutes just copy-pasting from Stackoverflow.

It hurts my heart to discover that Haskell sucks so badly even at simplest tasks. I do not understand why people use it for anything, honestly.

from req.

uzhas-sovka avatar uzhas-sovka commented on August 28, 2024

Default route is obvious.

  1. Google search "Haskell https", req is second link.
  2. Open req.
  3. Searching for cookies (I have them already). OOPS.

I understand that the main point of your library was completely different. But now it's in the wild and faced people with almost zero Haskell knowledge.

from req.

rgrover avatar rgrover commented on August 28, 2024

I wish to use cookies across requests. I am aware that a CookieJar can be obtained from a response. But to merge cookies across requests, I need updateCookieJar from Network.HTTP.Client. updateCookieJar requires a Request parameter, which isn't exposed by req. It would be very helpful if req could expose the underlying Request. Thanks.

from req.

kindaro avatar kindaro commented on August 28, 2024

To give a real world example: I was confronted by the need to emulate a browser state, and I ended up threading an MVar through, like this:

jar <- newMVar (mempty @CookieJar)
…
post jar … >>= \ response -> do …
…
where
  post :: MVar CookieJar -> Url 'Http -> ByteString -> IO BsResponse
  post cookieJarMVar url body = modifyMVar cookieJarMVar \ jar -> do
    response <- runReq httpConfig $ req POST url (ReqBodyBs body) (Proxy @BsResponse) (cookieJar jar)
    return (responseCookieJar response, response)

I wrapped all the methods I need like this. It works fine.

I am not sure if this package needs to incorporate this feature, but it seems to be a common use case and rolling out the wrappers takes some typing. @mrkkrp you are in the best position to judge if the code to this end should be admitted to the library, but surely at least some examples and directions may be given.

from req.

rgrover avatar rgrover commented on August 28, 2024

@kindaro: Thanks. Yes, I am able to reuse the cookies returned in one response for the following request. The above is sufficient If all responses contained 'set-cookie' values for the same set of cookies. But if different responses update subsets of the cookie-jar, then cookies need to be accumulated across requests. In the case, one would need to use updateCookieJar, which requires a Request object. Unfortunately, req does not expose the underlying Request.

from req.

kindaro avatar kindaro commented on August 28, 2024

Oh I see, so you have some requests that do not send back a cookie jar. At first I did not realize that.

It looks like some sort of a monad here, a hybrid between Writer and State.

from req.

mrkkrp avatar mrkkrp commented on August 28, 2024

Am I correct that we could solve (or at least alleviate) the issue by adding a new method to the HttpResponse type class which would allow us to get the Request used to obtain the response?

from req.

hughjfchen avatar hughjfchen commented on August 28, 2024

I think you can extract the cookieJar from response after the request and put it into a State monad. You can merge multi cookieJar across requests by getting the previous one and <> the current one because cookieJar is the instance of monoid if I remember correctly.

from req.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.