-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deno lacks a cookie jar for fetch
#5862
Comments
I agree. Deno ought to behave exactly as a browser does when it comes to the |
it's currently possible to implement a cookie jar on userland. const res = await fetch('https://example.com/set-cookie');
const cookies = res.headers.get('set-cookie')
// Implement your jar logic
const headers = new Headers();
headers.set('Cookie', cookies); // get from jar
const res = await fetch('https://example.com/set-cookie', { headers }); It should be easy to implement something like |
If Deno's |
It's forbidden on the browser, it wouldn't make sense to make that limitation on a server side HTTP client to be honest. Deno should match the spec where it makes sense to match it. The same way we had to go around the spec for |
I fiddled around a bit with Deno and Postman-Echo. Deno sends cookie headers. I must be missing something. (I'm trying to rewrite https://github.com/legowerewolf/ao3-fetch-js for Deno and running into snags in the login process.) Still, though, an actual built-in cookie jar, the way the browser does it, would be appreciated. |
I have the same issue. I am using Deno to send cookie headers and when I test it on postman I can see the cookie header but for some reason, the cookie doesn't work. |
I have the same issue as well. Lack of cookie support for the fetch API is the main reason I haven't been able to move over to deno. This functionality would be great to have! |
Hi |
Parsing cookie in result of fetch is a big pain - res.headers.get('cookie') returns all cookies comma separated - which is impractical to use as there can be comma within the cookie description as well - like
Not sure how to parse cookie to extract out all key value pairs safely. |
@shivam-tripathi use |
@bartlomieju I am guessing you want to point to getCookies function in https://deno.land/[email protected]/http/cookie.ts. res.headers.get("set-cookie")?.split(",")
.filter((c) => c.indexOf("GMT") == -1) // till now I've only run into Expires which has additional comma
.map((c) => c.split(";")[0].split("="))
.forEach(([k, v]) => this.cookieMap[k.trim()] = v.trim()); It would be best if res.headers.get("cookie") could return an array, but I am unsure it that's possible with the spec. Edit: Changed headers.get('cookie') to headers.get('set-cookie') |
@shivam-tripathi yes I meant |
@shivam-tripathi Are you talking about const setCookieHeaders = [...headers.entries()].filter(([k]) => k === 'set-cookie').map(([k, v]) => v); |
@lucacasonato Hey, yes you're right I meant |
@shivam-tripathi The behavior of Headers#get() is defined by WHATWG.
|
One can now use the following as a workaround: import makeFetchCookie from "npm:fetch-cookie";
const fetchCookie = makeFetchCookie(fetch); |
What are the current standings, from both the Deno team and the community, on supporting automatic cookie handling in the Fetch API? Do we want it? Personally, I'd like to have it implemented, same as the browser and within Deno to ensure correctness and quality. However, it'd come with added complexity and security concerns. AFAIK, no other server-side JS runtime has this functionality native. There could be good reasons for this, as previously mentioned, but this could be an opportunity for Deno 👀 |
so... shouldn't Deno introduce a new |
https://deno.land/x/another_cookiejar/mod.ts This library offers a fetch wrapper that retain cookies. This library also provides a simple cookiejar; |
Could an option be added to |
Deno should store cookies on a per-run basis (and optionally have methods in the Deno namespace for export/import of cookies) so that it's possible to make a series of requests that depend on cookies.
Right now, a flow like the following would be impossible:
Yes, I'm aware of
std/http/cookie
. No, it's not what I need - this is not a server. It's a client.The text was updated successfully, but these errors were encountered: