workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🐛 Bug Report — Playground: Multiple `Set-Cookie` headers not shown in raw HTTP response

Open tien opened this issue 1 year ago • 6 comments

Setting multiple cookie via headers will only have the final set cookie sent

reproduction

tien avatar Feb 19 '24 04:02 tien

Quick check on workerd shows that, at least in the local dev environment, both set-cookie headers are being returned with no problem. Interestingly, tho, the first one comes out encoded as Set-Cookie, while the second comes through lower-case as set-cookie.

Will need to check the production environment to see if something there is causing us to drop Set-Cookie headers. @kentonv ... any immediate ideas here? Is this an artifact of the workers-playground or an actual runtime issue? it's difficult to tell immediately.

jasnell avatar Feb 22 '24 02:02 jasnell

Looking at the reproduction link, when sending a request via the Preview tab of the playground, I do receive both Set-Cookie headers in DevTools. However, if I send a request via the HTTP tab, I only see set-cookie: bar=2. I think this is because of this code here: https://github.com/cloudflare/workers-sdk/blob/ef0642796dbe17b30fd7b83ccfd3efc651ce0a1a/packages/playground-preview-worker/src/index.ts#L70-L73 ...which prefixes all HTTP headers in raw-HTTP-requests with a prefix. I'll transfer this over to workers-sdk, since I think this is an issue with the playground specifically. 👍 /cc @penalosa

mrbbot avatar Feb 22 '24 10:02 mrbbot

@mrbbot thanks for looking into this. I'm also getting this issue when running worker locally via wrangler dev, haven't tested this in a deployed environment yet.

tien avatar Feb 23 '24 08:02 tien

@mrbbot I've just tested this on a deployed worker & the behaviour remains the same, only the final set cookie is sent to the client.

tien avatar Feb 24 '24 06:02 tien

@tien I can reproduce this in the Playground, but I can't seem to repro this with a deployed worker or with wrangler dev. I deployed your reproduction code at https://workers-playground-sparkling-field-1b7b.s.workers.dev, and that seems to correctly set both foo and bar cookies in the response. Could you link a reproduction of the issue with a deployed Worker?

penalosa avatar Feb 26 '24 11:02 penalosa

@penalosa okay so did some digging, and you are right cloudflare worker behave correctly once deployed.

I'm using trpc and this appears to be an issue with the library that was never fixed trpc/trpc#2312

It just so happen that Cloudflare Worker playground have the exact same issue, sorry if I've sent you on a wild goose hunt 😅

tien avatar Feb 26 '24 14:02 tien