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

undici fetch overwritten? #4057

Closed
DianomiJH opened this issue Aug 8, 2023 · 4 comments
Closed

undici fetch overwritten? #4057

DianomiJH opened this issue Aug 8, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@DianomiJH
Copy link

What version of Bun is running?

0.7.3

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

I'm trying to use Bun as a dev server as using AWS SAM cli isn't suitable, but I'm not quite ready to use it in production. In production, I need access to the 'Set-Cookie' header, so I'm using undici fetch (have also tried node-fetch) to get access to it as node18 doesn't have a inbuilt way of getting the Set-Cookie header. But when I'm using Bun as a dev server, it seems to overwrite the fetch import and throws an error 'TypeError: headers.getSetCookie is not a function.' (for undici, something similar about headers.raw is not a function in node-fetch)

it should be relatively easy to reproduce

import { fetch } from 'undici';

async function test() {
const response = await fetch('www.url-that-sets-cookie.com');
const setCookieHeader = response.headers.getSetCookie();
// TypeError: response.headers.getSetCookie is not a function.
}

test()

or from node-fetch:

import fetch from 'node-fetch';

async function test() {
const response = await fetch('www.url-that-sets-cookie.com');
const setCookieHeader = response.headers.raw()['set-cookie'];
// TypeError: response.headers.raw is not a function.
}

test()

What is the expected behavior?

I should be able to use undici fetch without Bun overwriting it (or at least have the same features when it's overwritten)

What do you see instead?

TypeError: response.headers.getSetCookie is not a function.

Additional information

possibly related commit? 2c0fd28...ba6908a

@DianomiJH DianomiJH added the bug Something isn't working label Aug 8, 2023
@Jarred-Sumner
Copy link
Collaborator

Bun is intentionally overwriting undici so that it uses the global fetch

However, we disabled getSetCookie() on Headers because it wasn't clear whether WHATWG would choose getAll or getSetCookie. We'll go ahead and enable getSetCookie.

@Jarred-Sumner
Copy link
Collaborator

This will be available once the next canary build finishes compiling (~1 hour)

bun upgrade --canary

@DianomiJH
Copy link
Author

Amazing, Thanks @Jarred-Sumner

trnxdev pushed a commit to trnxdev/bun that referenced this issue Aug 9, 2023
@battall
Copy link

battall commented Sep 17, 2023

i think this shouldn't be enabled when undici imported, because undici have other features that is needed besides fetch, like i cant use dispatcher or other options from undici, or the experimental h2 support, bun just overrides it. and not just fetch but other methods like undici.request, undici.stream overwritten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants