Skip to content

Commit

Permalink
fix entires iteration for cookies (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schniz committed May 24, 2023
1 parent 46f2862 commit b02cec8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-berries-hunt.md
@@ -0,0 +1,5 @@
---
'@edge-runtime/primitives': patch
---

fix entries iteration on Headers
8 changes: 8 additions & 0 deletions packages/integration-tests/tests/headers.test.ts
Expand Up @@ -10,3 +10,11 @@ test('sets header calling Headers constructor', async () => {
headers.set('cookie', 'hello=world')
expect(headers.get('cookie')).toBe('hello=world')
})

test('multiple headers', async () => {
const headers = new Headers()
headers.append('set-cookie', 'foo=chocochip')
headers.append('set-cookie', 'bar=chocochip')
expect(headers.get('set-cookie')).toBe('foo=chocochip, bar=chocochip')
expect([...headers]).toEqual([['set-cookie', 'foo=chocochip, bar=chocochip']])
})
5 changes: 5 additions & 0 deletions packages/primitives/src/primitives/fetch.js
Expand Up @@ -27,8 +27,13 @@ class Request extends BaseRequest {

const __entries = HeadersModule.Headers.prototype.entries
HeadersModule.Headers.prototype.entries = function* () {
let sentSetCookie = false
for (const [key, value] of __entries.call(this)) {
if (key === 'set-cookie') {
if (sentSetCookie) {
continue
}
sentSetCookie = true
const cookies = this.getSetCookie()
yield [key, cookies.join(', ')]
} else {
Expand Down

1 comment on commit b02cec8

@vercel
Copy link

@vercel vercel bot commented on b02cec8 May 24, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

edge-runtime – ./

edge-runtime.vercel.app
edge-runtime-git-main.vercel.sh
edge-runtime.vercel.sh

Please sign in to comment.