Comments (8)
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.
Default route is obvious.
- Google search "Haskell https", req is second link.
- Open req.
- 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.
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.
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.
@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.
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.
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.
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)
- Make Req an instance of MonadUnliftIO HOT 2
- Cannot perform a request with url containing braces HOT 7
- Hard to pass Link header URIs back into req HOT 5
- When req fails with a StatusCodeException the body is truncated HOT 4
- Get access to the Request HOT 5
- Add `MonadMask` instance for `Req`?
- ConnectionTimeout with "req" even though "curl" and browser work just fine HOT 1
- Set a retrying limit by default for request timeouts HOT 2
- not installable on ghc 9.0.1 due to reliance on base <4.15 HOT 3
- Support retry 0.9 HOT 1
- How can I retrieve the exact URL with query parameters? Possible limitation? HOT 6
- Interface with ToForm and FromForm HOT 2
- Support for GHC 9.2 HOT 2
- Not compatible with transformers-0.6 HOT 1
- Couldn't find a way to call odata services HOT 1
- No way to force encoding of a segment HOT 1
- Couldn't match expected type ‘NC.TLSSettings’ HOT 1
- How can I retry the request even if it errors out? HOT 2
- unexpected program termination HOT 2
- Inspecting Request Created by `req` Function HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from req.