D
Deno

help

std/http/setCookie doesn't work?

Jjcayzac1/5/2024
It seems to only support single cookies:
import * as cookies from "https://deno.land/std@0.211.0/http/cookie.ts"
var h = new Headers()

cookies.setCookie(h, {name: 'foo', value: 'FOO'})
// Headers { "set-cookie": "foo=FOO" }
// OK (works as expected)

cookies.setCookie(h, {name: 'bar', value: 'BAR'})
// Headers { "set-cookie": "bar=BAR" }
// Not OK: Cookie `foo` was deleted for some reason!

cookies.setCookie(h, [{name: 'x', value: 'X'}, {name: 'y', value: 'Y'}])
// Headers { "set-cookie": "bar=BAR" }
// Not OK: None of the cookies were set
import * as cookies from "https://deno.land/std@0.211.0/http/cookie.ts"
var h = new Headers()

cookies.setCookie(h, {name: 'foo', value: 'FOO'})
// Headers { "set-cookie": "foo=FOO" }
// OK (works as expected)

cookies.setCookie(h, {name: 'bar', value: 'BAR'})
// Headers { "set-cookie": "bar=BAR" }
// Not OK: Cookie `foo` was deleted for some reason!

cookies.setCookie(h, [{name: 'x', value: 'X'}, {name: 'y', value: 'Y'}])
// Headers { "set-cookie": "bar=BAR" }
// Not OK: None of the cookies were set
Also, it assumes the Headers object is a container for response headers. For request headers it the right header would be cookie:, not set-cookie:.
Rrazzi1/5/2024
That is indeed weird behavior, however you can pass multiple cookies using the Headers constructor: https://deno.land/std@0.211.0/http/cookie.ts?s=getSetCookies#Examples
const headers = new Headers([
["Set-Cookie", "lulu=meow; Secure; Max-Age=3600"],
["Set-Cookie", "booya=kasha; HttpOnly; Path=/"],
]);
const headers = new Headers([
["Set-Cookie", "lulu=meow; Secure; Max-Age=3600"],
["Set-Cookie", "booya=kasha; HttpOnly; Path=/"],
]);
(as a workaround)
Jjcayzac1/5/2024
Right, but then I don't need std/http. The lack of a cookie jar for fetch() is pretty sad. I would put that pretty high on my wishlist…
Mmarvinh.1/5/2024
I'd consider this a bug. Can you file an issue for that on the std repo? cc @iuioiua
Jjcayzac1/5/2024
Ah, the bug is in how Deno.inspect() reports the content of the Headers object, not in the std/http library!
No description

Looking for more? Join the community!

Recommended Posts
Abort signals and node compatibilityDeno and Node's `AbortSignal` types are not compatible. I have verified that I can use a deno Abortdeployctl error: TypeError: request or response body errorHey, I'm getting an error when trying to deploy to a project error: TypeError: request or response bdrizzle orm for deno and sqlite?does drizzle orm work with sqlite and deno?deno queues on deployDoes anyone have a simple example if deno queues + routing that works on demo deploycompile to target, 'unzip' not found.I am on linux ubuntu 22 I downloaded, uninstalled reinstalled, written to path unzip. however no matRecommendations for interacting with Excel sheets (.xlsx) and GraphQL?I want to use Deno in production. Specifically, I'm looking into building a script that reads a `.xlTrouble with Deno importsWhat's wrong with my import? The link is valid and I cached it. (https://deno.land/x/deno_dom@v0.1.How to format on save with devcontainerI'd like to automatically format my code when saving, but it's not working. devcontainer.json ```jsHow does form submission work?I'm following the tutorial: https://fresh.deno.dev/docs/getting-started/form-submissions It says: >Won't install `npm:@supabase/ssr`I'm trying to build something with Fresh and Supabase and would like to use the [`@supabase/ssr`](ht`RangeError: Offset is outside the bounds of the DataView` when trying to encrypt with AES-CRTHi, I'm trying to encrypt some files with aes128-crt, but I always get the error below. (Even if I jAny way for VS Code to auto-complete library subdirectory in import?Is there any way for VS Code to suggest subdirectory in a package (especially for npm package) when get hours & minutes in a specific timezoneMaybe I search the wrong way, but all I'd like to do is to use a specific timezone in my project runConnection refused when creating a local API serverI'm following [Simple API server | Deno Docs](https://docs.deno.com/deploy/tutorials/simple-api "Sim