elysia icon indicating copy to clipboard operation
elysia copied to clipboard

Reading a cookie value results in the cookie beeing set again

Open david-plugge opened this issue 1 year ago • 7 comments

What version of Elysia is running?

1.1.17

What platform is your computer?

Linux 5.15.153.1-microsoft-standard-WSL2 x86_64 unknown

What steps can reproduce the bug?

When reading a cookie that is present a set-cookie header is added to the response, even when no new cookie value is set.

To reproduce just create a new Elysia project (bun create elysie) and copy the following code into src/index.ts

import { Elysia } from 'elysia';

new Elysia()
	.get('/', () => 'Hello Elysia')

	.get('/set', ({ cookie: { test } }) => {
		test.value = Math.random().toString();

		return {
			value: test.value,
		};
	})
	.get('/get', ({ cookie: { test } }) => {
		return {
			value: test.value,
		};
	})

	.listen(3000, (server) => {
		console.log(`🦊 Elysia is running at ${server.url}`);
	});

Steps to reproduce:

  1. visit http://localhost:3000/get -> set-cookie header is not present
  2. visit http://localhost:3000/set -> set-cookie header is present
  3. visit http://localhost:3000/get -> set-cookie header is present

What is the expected behavior?

The cookie is not set again

What do you see instead?

The cookie is set again.

Additional information

The session cookie i use in my session service gets set over and over. That itself is not that big of a deal in terms of functionality, but due to missing informations about the cookie lifetime for example the cookie is always set using the default options (no path, no domain, no secure, no httpOnly, ...).

Have you try removing the node_modules and bun.lockb and try again yet?

yes

david-plugge avatar Sep 29 '24 13:09 david-plugge