@whatwg-node/node-fetch
Advanced tools
Comparing version 0.4.0-alpha-20230515125426-a472464 to 0.4.0-alpha-20230515131253-e1eec20
@@ -10,2 +10,3 @@ "use strict"; | ||
const zlib_1 = require("zlib"); | ||
const AbortError_js_1 = require("./AbortError.js"); | ||
const Blob_js_1 = require("./Blob.js"); | ||
@@ -21,2 +22,22 @@ const Request_js_1 = require("./Request.js"); | ||
} | ||
function getResponseForDataUri(url) { | ||
const [mimeType = 'text/plain', ...datas] = url.pathname.split(','); | ||
const data = decodeURIComponent(datas.join(',')); | ||
if (mimeType.endsWith(BASE64_SUFFIX)) { | ||
const buffer = Buffer.from(data, 'base64url'); | ||
const realMimeType = mimeType.slice(0, -BASE64_SUFFIX.length); | ||
const file = new Blob_js_1.PonyfillBlob([buffer], { type: realMimeType }); | ||
return new Response_js_1.PonyfillResponse(file, { | ||
status: 200, | ||
statusText: 'OK', | ||
}); | ||
} | ||
return new Response_js_1.PonyfillResponse(data, { | ||
status: 200, | ||
statusText: 'OK', | ||
headers: { | ||
'content-type': mimeType, | ||
}, | ||
}); | ||
} | ||
function getRequestFnForProtocol(protocol) { | ||
@@ -42,22 +63,3 @@ switch (protocol) { | ||
if (url.protocol === 'data:') { | ||
const [mimeType = 'text/plain', ...datas] = url.pathname.split(','); | ||
const data = decodeURIComponent(datas.join(',')); | ||
if (mimeType.endsWith(BASE64_SUFFIX)) { | ||
const buffer = Buffer.from(data, 'base64url'); | ||
const realMimeType = mimeType.slice(0, -BASE64_SUFFIX.length); | ||
const file = new Blob_js_1.PonyfillBlob([buffer], { type: realMimeType }); | ||
const response = new Response_js_1.PonyfillResponse(file, { | ||
status: 200, | ||
statusText: 'OK', | ||
}); | ||
resolve(response); | ||
return; | ||
} | ||
const response = new Response_js_1.PonyfillResponse(data, { | ||
status: 200, | ||
statusText: 'OK', | ||
headers: { | ||
'content-type': mimeType, | ||
}, | ||
}); | ||
const response = getResponseForDataUri(url); | ||
resolve(response); | ||
@@ -80,3 +82,2 @@ return; | ||
const nodeRequest = requestFn(fetchRequest.url, { | ||
// signal: fetchRequest.signal will be added when v14 reaches EOL | ||
method: fetchRequest.method, | ||
@@ -129,2 +130,6 @@ headers: nodeHeaders, | ||
}); | ||
// TODO: will be removed after v16 reaches EOL | ||
nodeRequest.once('abort', (reason) => { | ||
reject(new AbortError_js_1.PonyfillAbortError(reason)); | ||
}); | ||
nodeRequest.once('error', reject); | ||
@@ -131,0 +136,0 @@ if (nodeReadable) { |
@@ -7,2 +7,3 @@ import { createReadStream } from 'fs'; | ||
import { createBrotliDecompress, createGunzip, createInflate } from 'zlib'; | ||
import { PonyfillAbortError } from './AbortError.js'; | ||
import { PonyfillBlob } from './Blob.js'; | ||
@@ -18,2 +19,22 @@ import { PonyfillRequest } from './Request.js'; | ||
} | ||
function getResponseForDataUri(url) { | ||
const [mimeType = 'text/plain', ...datas] = url.pathname.split(','); | ||
const data = decodeURIComponent(datas.join(',')); | ||
if (mimeType.endsWith(BASE64_SUFFIX)) { | ||
const buffer = Buffer.from(data, 'base64url'); | ||
const realMimeType = mimeType.slice(0, -BASE64_SUFFIX.length); | ||
const file = new PonyfillBlob([buffer], { type: realMimeType }); | ||
return new PonyfillResponse(file, { | ||
status: 200, | ||
statusText: 'OK', | ||
}); | ||
} | ||
return new PonyfillResponse(data, { | ||
status: 200, | ||
statusText: 'OK', | ||
headers: { | ||
'content-type': mimeType, | ||
}, | ||
}); | ||
} | ||
function getRequestFnForProtocol(protocol) { | ||
@@ -39,22 +60,3 @@ switch (protocol) { | ||
if (url.protocol === 'data:') { | ||
const [mimeType = 'text/plain', ...datas] = url.pathname.split(','); | ||
const data = decodeURIComponent(datas.join(',')); | ||
if (mimeType.endsWith(BASE64_SUFFIX)) { | ||
const buffer = Buffer.from(data, 'base64url'); | ||
const realMimeType = mimeType.slice(0, -BASE64_SUFFIX.length); | ||
const file = new PonyfillBlob([buffer], { type: realMimeType }); | ||
const response = new PonyfillResponse(file, { | ||
status: 200, | ||
statusText: 'OK', | ||
}); | ||
resolve(response); | ||
return; | ||
} | ||
const response = new PonyfillResponse(data, { | ||
status: 200, | ||
statusText: 'OK', | ||
headers: { | ||
'content-type': mimeType, | ||
}, | ||
}); | ||
const response = getResponseForDataUri(url); | ||
resolve(response); | ||
@@ -77,3 +79,2 @@ return; | ||
const nodeRequest = requestFn(fetchRequest.url, { | ||
// signal: fetchRequest.signal will be added when v14 reaches EOL | ||
method: fetchRequest.method, | ||
@@ -126,2 +127,6 @@ headers: nodeHeaders, | ||
}); | ||
// TODO: will be removed after v16 reaches EOL | ||
nodeRequest.once('abort', (reason) => { | ||
reject(new PonyfillAbortError(reason)); | ||
}); | ||
nodeRequest.once('error', reject); | ||
@@ -128,0 +133,0 @@ if (nodeReadable) { |
{ | ||
"name": "@whatwg-node/node-fetch", | ||
"version": "0.4.0-alpha-20230515125426-a472464", | ||
"version": "0.4.0-alpha-20230515131253-e1eec20", | ||
"description": "Fetch API implementation for Node", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"@whatwg-node/events": "0.1.0-alpha-20230515125426-a472464", | ||
"@whatwg-node/events": "0.1.0-alpha-20230515131253-e1eec20", | ||
"busboy": "^1.6.0", | ||
@@ -9,0 +9,0 @@ "fast-querystring": "^1.1.1", |
128725
62
3158
+ Added@whatwg-node/events@0.1.0-alpha-20230515131253-e1eec20(transitive)
- Removed@whatwg-node/events@0.1.0-alpha-20230515125426-a472464(transitive)
Updated@whatwg-node/events@0.1.0-alpha-20230515131253-e1eec20