Skip to content
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

fix iterating headers with set-cookie #4048

Merged
merged 6 commits into from
Aug 8, 2023

Conversation

dylan-conway
Copy link
Member

What does this PR do?

before:

const headers = new Headers();
headers.append("Set-Cookie", "cookies");
headers.append("Content-Type", "application/json");

console.log([...headers]);
// output: [ [ "content-type", "application/json" ], [ "content-type", "application/json" ] ]

after:

// output: [ [ "content-type", "application/json" ], [ "set-cookie", "cookies" ] ]

How did you verify your code works?

updated and added test for headers with set-cookie

@paperclover
Copy link
Member

paperclover commented Aug 7, 2023

This will close #600 :) I mispoke, it will only close it for bun --bun run dev

There is a bug in building that still has to get investigated.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2023

@dylan-conway 4 files with test failures on bun-darwin-aarch64:

  • test/bundler/esbuild/default.test.ts
  • test/cli/install/bun-install.test.ts
  • test/js/bun/test/test-test.test.ts
  • test/regression/issue/4011.test.ts

View test output

#4c17d384f6ffb9b69058ad3f7cb8f7bc83392ad0

@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2023

@dylan-conway 2 files with test failures on linux-x64-baseline:

  • test/js/bun/test/test-test.test.ts
  • test/js/third_party/prisma/prisma.test.ts

View test output

#4c17d384f6ffb9b69058ad3f7cb8f7bc83392ad0

@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2023

@dylan-conway 3 files with test failures on linux-x64:

  • test/js/bun/test/test-test.test.ts
  • test/js/third_party/prisma/prisma.test.ts
  • test/js/web/fetch/fetch.test.ts

View test output

#4c17d384f6ffb9b69058ad3f7cb8f7bc83392ad0

@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2023

@dylan-conway 7 files with test failures on bun-darwin-x64-baseline:

  • test/js/bun/spawn/spawn-streaming-stdin.test.ts
  • test/js/bun/spawn/spawn-streaming-stdout.test.ts
  • test/js/bun/sqlite/sqlite.test.js
  • test/js/bun/test/test-test.test.ts
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setInterval.test.js
  • test/js/web/timers/setTimeout.test.js

View test output

#4c17d384f6ffb9b69058ad3f7cb8f7bc83392ad0

for (auto& header : m_headers->m_headers)
m_keys.uncheckedAppend(header.asciiLowerCaseName());
std::sort(m_keys.begin(), m_keys.end(), WTF::codePointCompareLessThan);
if (hasSetCookie)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to pay this performance overhead here? Wouldn't it be fine if we put the Set-Cookie header either first or last?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was also expected in the spec for keys to be unique which isn’t true for set-cookies

I think we should just always put it at the end and call it a day. Each call to next() shouldn’t slow it down

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to append after the sort

Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should be moved to HTTPHeaderMap to avoid duplicate work

@Jarred-Sumner Jarred-Sumner merged commit 1239c94 into main Aug 8, 2023
@Jarred-Sumner Jarred-Sumner deleted the dylan/fix-set-cookie-headers branch August 8, 2023 02:32
@Jarred-Sumner
Copy link
Collaborator

Thank you

trnxdev pushed a commit to trnxdev/bun that referenced this pull request Aug 9, 2023
* fix iterating headers with `set-cookie`

* a test

* move work to `HTTPHeaderMap::set`

* append set-cookie after sort

* remove compare function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants