Skip to content

Commit

Permalink
fix(fetch): add duplex to RequestInit if not provided for new undici
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Oct 28, 2022
1 parent 6113c70 commit a8a7cfc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-toes-switch.md
@@ -0,0 +1,5 @@
---
'@whatwg-node/fetch': patch
---

Fix for new undici
6 changes: 6 additions & 0 deletions packages/fetch/dist/create-node-ponyfill.js
Expand Up @@ -122,6 +122,9 @@ module.exports = function createNodePonyfill(opts = {}) {
class Request extends OriginalRequest {
constructor(requestOrUrl, options) {
if (typeof requestOrUrl === "string" || requestOrUrl instanceof URL) {
if (options != null && typeof options === "object" && !options.duplex) {
options.duplex = 'half';
}
super(requestOrUrl, options);
const contentType = this.headers.get("content-type");
if (contentType && contentType.startsWith("multipart/form-data")) {
Expand All @@ -140,6 +143,9 @@ module.exports = function createNodePonyfill(opts = {}) {

const fetch = function (requestOrUrl, options) {
if (typeof requestOrUrl === "string" || requestOrUrl instanceof URL) {
if (options != null && typeof options === "object" && !options.duplex) {
options.duplex = 'half';
}
// We cannot use our ctor because it leaks on Node 18's global fetch
return originalFetch(requestOrUrl, options);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fetch/package.json
Expand Up @@ -24,7 +24,7 @@
"form-data-encoder": "^1.7.1",
"formdata-node": "^4.3.1",
"node-fetch": "^2.6.7",
"undici": "^5.10.0",
"undici": "^5.12.0",
"web-streams-polyfill": "^3.2.0"
},
"publishConfig": {
Expand Down
10 changes: 6 additions & 4 deletions yarn.lock
Expand Up @@ -5788,10 +5788,12 @@ unbox-primitive@^1.0.2:
has-symbols "^1.0.3"
which-boxed-primitive "^1.0.2"

undici@^5.10.0:
version "5.10.0"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.10.0.tgz#dd9391087a90ccfbd007568db458674232ebf014"
integrity sha512-c8HsD3IbwmjjbLvoZuRI26TZic+TSEe8FPMLLOkN1AfYRhdjnKBU6yL+IwcSCbdZiX4e5t0lfMDLDCqj4Sq70g==
undici@^5.12.0:
version "5.12.0"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.12.0.tgz#c758ffa704fbcd40d506e4948860ccaf4099f531"
integrity sha512-zMLamCG62PGjd9HHMpo05bSLvvwWOZgGeiWlN/vlqu3+lRo3elxktVGEyLMX+IO7c2eflLjcW74AlkhEZm15mg==
dependencies:
busboy "^1.6.0"

unicode-canonical-property-names-ecmascript@^2.0.0:
version "2.0.0"
Expand Down

0 comments on commit a8a7cfc

Please sign in to comment.