diff --git a/.changeset/old-games-impress.md b/.changeset/old-games-impress.md new file mode 100644 index 0000000000..cb58109233 --- /dev/null +++ b/.changeset/old-games-impress.md @@ -0,0 +1,5 @@ +--- +'@whatwg-node/fetch': patch +--- + +Add ponyfills for Response.redirect, Response.json and Response.error diff --git a/packages/fetch/dist/create-node-ponyfill.js b/packages/fetch/dist/create-node-ponyfill.js index d3627344c6..a8cefd2009 100644 --- a/packages/fetch/dist/create-node-ponyfill.js +++ b/packages/fetch/dist/create-node-ponyfill.js @@ -319,5 +319,34 @@ module.exports = function createNodePonyfill(opts = {}) { } } + + if (!ponyfills.Response.redirect) { + ponyfills.Response.redirect = function (url, status = 302) { + return new ponyfills.Response(null, { + status, + headers: { + Location: url, + }, + }); + }; + } + if (!ponyfills.Response.json) { + ponyfills.Response.json = function (data, init = {}) { + return new ponyfills.Response(JSON.stringify(data), { + ...init, + headers: { + "Content-Type": "application/json", + ...init.headers, + }, + }); + }; + } + if (!ponyfills.Response.error) { + ponyfills.Response.error = function () { + return new ponyfills.Response(null, { + status: 500, + }); + }; + } return ponyfills; }