Deno: Deno lacks a cookie jar for `fetch`

Created on 26 May 2020  路  7Comments  路  Source: denoland/deno

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:

  1. No cookies sent; response sets cookie 1.
  2. Cookie 1 sent; response uses cookie 1 value somewhere in the body

Yes, I'm aware of std/http/cookie. No, it's not what I need - this is not a server. It's a client.

cli feat web

Most helpful comment

I agree. Deno ought to behave exactly as a browser does when it comes to the fetch() API.

All 7 comments

I agree. Deno ought to behave exactly as a browser does when it comes to the fetch() API.

Right now, a flow like the following would be impossible:

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 fetch-cookie

If Deno's fetch and headers APIs match specs, the Cookie header is one of the forbidden header names, and that won't work. I'm surprised that that library works after inspecting it.

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 Set-Cookie header.

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ry picture ry  路  3Comments

somombo picture somombo  路  3Comments

kitsonk picture kitsonk  路  3Comments

benjamingr picture benjamingr  路  3Comments

xueqingxiao picture xueqingxiao  路  3Comments