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
types: HeadersInit does not accept arrays as values, but it will work #388
Comments
It'll accept |
I guess another viewpoint is, should it accept an array of values? https://fetch.spec.whatwg.org/#headers-class appears to say no. |
The runtime is not intentionally designed to allow an array here. The reason it works is because of the general JavaScript behavior of being able to coerce anything to a string. |
Thanks for the insight Kenton, that makes sense. The issue is actually off the back of what Undici (through Miniflare) does - where they allow arrays as values, especially for setting multiple Someone reported this discrepancy on the Wrangler repo: cloudflare/workers-sdk#2743 The change in Undici is nodejs/undici#1598, but I can't really find anything to back that up as something that is supposed to be possible under the Fetch spec - it's also possible that change isn't strictly what causes the behaviour since they also have some |
Hey! 👋 I think we should keep these types the same for now, considering this is what TypeScript's |
This makes sense, but the current Whilst both will accept Shouldn't the |
HeadersInit
is defined astype HeadersInit = Headers | Iterable<Iterable<string>> | Record<string, string>
- the one that's of note isRecord<string, string>
.The runtime will accept an array as the value for a given key, and fold them into a single header by joining them with a comma, but the types don't allow this.
I assume it's defined here, and should instead be
Record<string, string | string[]>
.workerd/src/workerd/api/http.h
Line 134 in c0ea735
The text was updated successfully, but these errors were encountered: