@whatwg-node/node-fetch
Advanced tools
Comparing version 0.7.3 to 0.7.4-alpha-20241125124758-22623cd8c312a8c35092a436e5a2c631dd52f59d
@@ -24,3 +24,3 @@ "use strict"; | ||
try { | ||
const requestFn = getRequestFnForProtocol(fetchRequest.url); | ||
const requestFn = getRequestFnForProtocol(fetchRequest.parsedUrl?.protocol || fetchRequest.url); | ||
const nodeReadable = (fetchRequest.body != null | ||
@@ -36,8 +36,24 @@ ? (0, utils_js_1.isNodeReadable)(fetchRequest.body) | ||
} | ||
const nodeRequest = requestFn(fetchRequest.url, { | ||
method: fetchRequest.method, | ||
headers: nodeHeaders, | ||
signal: fetchRequest['_signal'] ?? undefined, | ||
agent: fetchRequest.agent, | ||
}); | ||
let nodeRequest; | ||
if (fetchRequest.parsedUrl) { | ||
nodeRequest = requestFn({ | ||
host: fetchRequest.parsedUrl.host, | ||
hostname: fetchRequest.parsedUrl.hostname, | ||
method: fetchRequest.method, | ||
path: fetchRequest.parsedUrl.pathname + (fetchRequest.parsedUrl.search || ''), | ||
port: fetchRequest.parsedUrl.port, | ||
protocol: fetchRequest.parsedUrl.protocol, | ||
headers: nodeHeaders, | ||
signal: fetchRequest['_signal'] ?? undefined, | ||
agent: fetchRequest.agent, | ||
}); | ||
} | ||
else { | ||
nodeRequest = requestFn(fetchRequest.url, { | ||
method: fetchRequest.method, | ||
headers: nodeHeaders, | ||
signal: fetchRequest['_signal'] ?? undefined, | ||
agent: fetchRequest.agent, | ||
}); | ||
} | ||
nodeRequest.once('response', nodeResponse => { | ||
@@ -73,3 +89,3 @@ let outputStream; | ||
if (fetchRequest.redirect === 'follow') { | ||
const redirectedUrl = new URL_js_1.PonyfillURL(nodeResponse.headers.location, fetchRequest.url); | ||
const redirectedUrl = new URL_js_1.PonyfillURL(nodeResponse.headers.location, fetchRequest.parsedUrl || fetchRequest.url); | ||
const redirectResponse$ = fetchNodeHttp(new Request_js_1.PonyfillRequest(redirectedUrl, fetchRequest)); | ||
@@ -76,0 +92,0 @@ resolve(redirectResponse$.then(redirectResponse => { |
@@ -5,2 +5,3 @@ "use strict"; | ||
const node_util_1 = require("node:util"); | ||
const disposablestack_1 = require("@whatwg-node/disposablestack"); | ||
const utils_js_1 = require("./utils.js"); | ||
@@ -114,6 +115,4 @@ class PonyfillIteratorObject { | ||
} | ||
[Symbol.dispose]() { | ||
if (typeof this.iterableIterator.return === 'function') { | ||
this.iterableIterator.return(); | ||
} | ||
[disposablestack_1.DisposableSymbols.dispose]() { | ||
this.iterableIterator.return?.(); | ||
} | ||
@@ -120,0 +119,0 @@ next(...[value]) { |
@@ -68,2 +68,17 @@ "use strict"; | ||
let ongoing = false; | ||
const readImpl = async (desiredSize) => { | ||
if (!started) { | ||
const controller = createController(desiredSize, this.readable); | ||
started = true; | ||
await underlyingSource?.start?.(controller); | ||
controller._flush(); | ||
if (controller._closed) { | ||
return; | ||
} | ||
} | ||
const controller = createController(desiredSize, this.readable); | ||
await underlyingSource?.pull?.(controller); | ||
controller._flush(); | ||
ongoing = false; | ||
}; | ||
this.readable = new stream_1.Readable({ | ||
@@ -75,17 +90,3 @@ read(desiredSize) { | ||
ongoing = true; | ||
return Promise.resolve().then(async () => { | ||
if (!started) { | ||
const controller = createController(desiredSize, this); | ||
started = true; | ||
await underlyingSource?.start?.(controller); | ||
controller._flush(); | ||
if (controller._closed) { | ||
return; | ||
} | ||
} | ||
const controller = createController(desiredSize, this); | ||
await underlyingSource?.pull?.(controller); | ||
controller._flush(); | ||
ongoing = false; | ||
}); | ||
return readImpl(desiredSize); | ||
}, | ||
@@ -162,2 +163,13 @@ destroy(err, callback) { | ||
} | ||
async pipeToWriter(writer) { | ||
try { | ||
for await (const chunk of this) { | ||
await writer.write(chunk); | ||
} | ||
await writer.close(); | ||
} | ||
catch (err) { | ||
await writer.abort(err); | ||
} | ||
} | ||
pipeTo(destination) { | ||
@@ -173,13 +185,3 @@ if (isPonyfillWritableStream(destination)) { | ||
const writer = destination.getWriter(); | ||
return Promise.resolve().then(async () => { | ||
try { | ||
for await (const chunk of this) { | ||
await writer.write(chunk); | ||
} | ||
await writer.close(); | ||
} | ||
catch (err) { | ||
await writer.abort(err); | ||
} | ||
}); | ||
return this.pipeToWriter(writer); | ||
} | ||
@@ -186,0 +188,0 @@ } |
@@ -8,2 +8,3 @@ "use strict"; | ||
const Headers_js_1 = require("./Headers.js"); | ||
const URL_js_1 = require("./URL.js"); | ||
function isRequest(input) { | ||
@@ -17,13 +18,22 @@ return input[Symbol.toStringTag] === 'Request'; | ||
constructor(input, options) { | ||
let url; | ||
let _url; | ||
let _parsedUrl; | ||
let bodyInit = null; | ||
let requestInit; | ||
if (typeof input === 'string') { | ||
url = input; | ||
_url = input; | ||
} | ||
else if (isURL(input)) { | ||
url = input.toString(); | ||
_parsedUrl = input; | ||
} | ||
else if (isRequest(input)) { | ||
url = input.url; | ||
if (input._parsedUrl) { | ||
_parsedUrl = input._parsedUrl; | ||
} | ||
else if (input._url) { | ||
_url = input._url; | ||
} | ||
else { | ||
_url = input.url; | ||
} | ||
bodyInit = input.body; | ||
@@ -37,2 +47,4 @@ requestInit = input; | ||
super(bodyInit, options); | ||
this._url = _url; | ||
this._parsedUrl = _parsedUrl; | ||
this.cache = requestInit?.cache || 'default'; | ||
@@ -54,3 +66,2 @@ this.credentials = requestInit?.credentials || 'same-origin'; | ||
this.duplex = requestInit?.duplex || 'half'; | ||
this.url = url || ''; | ||
this.destination = 'document'; | ||
@@ -62,9 +73,10 @@ this.priority = 'auto'; | ||
if (requestInit?.agent != null) { | ||
const protocol = _parsedUrl?.protocol || _url || this.url; | ||
if (requestInit.agent === false) { | ||
this.agent = false; | ||
} | ||
else if (this.url.startsWith('http:/') && requestInit.agent instanceof http_1.Agent) { | ||
else if (protocol.startsWith('http:') && requestInit.agent instanceof http_1.Agent) { | ||
this.agent = requestInit.agent; | ||
} | ||
else if (this.url.startsWith('https:/') && requestInit.agent instanceof https_1.Agent) { | ||
else if (protocol.startsWith('https:') && requestInit.agent instanceof https_1.Agent) { | ||
this.agent = requestInit.agent; | ||
@@ -87,3 +99,26 @@ } | ||
referrerPolicy; | ||
url; | ||
_url; | ||
get url() { | ||
if (this._url == null) { | ||
if (this._parsedUrl) { | ||
this._url = this._parsedUrl.toString(); | ||
} | ||
else { | ||
throw new TypeError('Invalid URL'); | ||
} | ||
} | ||
return this._url; | ||
} | ||
_parsedUrl; | ||
get parsedUrl() { | ||
if (this._parsedUrl == null) { | ||
if (this._url != null) { | ||
this._parsedUrl = new URL_js_1.PonyfillURL(this._url); | ||
} | ||
else { | ||
throw new TypeError('Invalid URL'); | ||
} | ||
} | ||
return this._parsedUrl; | ||
} | ||
duplex; | ||
@@ -90,0 +125,0 @@ agent; |
@@ -72,3 +72,4 @@ "use strict"; | ||
} | ||
[Symbol.toStringTag] = 'URL'; | ||
} | ||
exports.PonyfillURL = PonyfillURL; |
@@ -17,7 +17,3 @@ "use strict"; | ||
} | ||
const obj = {}; | ||
headers.forEach((value, key) => { | ||
obj[key] = value; | ||
}); | ||
return obj; | ||
return Object.fromEntries(headers.entries()); | ||
} | ||
@@ -24,0 +20,0 @@ function defaultHeadersSerializer(headers, onContentLength) { |
@@ -21,3 +21,3 @@ import { request as httpRequest } from 'http'; | ||
try { | ||
const requestFn = getRequestFnForProtocol(fetchRequest.url); | ||
const requestFn = getRequestFnForProtocol(fetchRequest.parsedUrl?.protocol || fetchRequest.url); | ||
const nodeReadable = (fetchRequest.body != null | ||
@@ -33,8 +33,24 @@ ? isNodeReadable(fetchRequest.body) | ||
} | ||
const nodeRequest = requestFn(fetchRequest.url, { | ||
method: fetchRequest.method, | ||
headers: nodeHeaders, | ||
signal: fetchRequest['_signal'] ?? undefined, | ||
agent: fetchRequest.agent, | ||
}); | ||
let nodeRequest; | ||
if (fetchRequest.parsedUrl) { | ||
nodeRequest = requestFn({ | ||
host: fetchRequest.parsedUrl.host, | ||
hostname: fetchRequest.parsedUrl.hostname, | ||
method: fetchRequest.method, | ||
path: fetchRequest.parsedUrl.pathname + (fetchRequest.parsedUrl.search || ''), | ||
port: fetchRequest.parsedUrl.port, | ||
protocol: fetchRequest.parsedUrl.protocol, | ||
headers: nodeHeaders, | ||
signal: fetchRequest['_signal'] ?? undefined, | ||
agent: fetchRequest.agent, | ||
}); | ||
} | ||
else { | ||
nodeRequest = requestFn(fetchRequest.url, { | ||
method: fetchRequest.method, | ||
headers: nodeHeaders, | ||
signal: fetchRequest['_signal'] ?? undefined, | ||
agent: fetchRequest.agent, | ||
}); | ||
} | ||
nodeRequest.once('response', nodeResponse => { | ||
@@ -70,3 +86,3 @@ let outputStream; | ||
if (fetchRequest.redirect === 'follow') { | ||
const redirectedUrl = new PonyfillURL(nodeResponse.headers.location, fetchRequest.url); | ||
const redirectedUrl = new PonyfillURL(nodeResponse.headers.location, fetchRequest.parsedUrl || fetchRequest.url); | ||
const redirectResponse$ = fetchNodeHttp(new PonyfillRequest(redirectedUrl, fetchRequest)); | ||
@@ -73,0 +89,0 @@ resolve(redirectResponse$.then(redirectResponse => { |
import { inspect } from 'node:util'; | ||
import { DisposableSymbols } from '@whatwg-node/disposablestack'; | ||
import { isIterable } from './utils.js'; | ||
@@ -110,6 +111,4 @@ export class PonyfillIteratorObject { | ||
} | ||
[Symbol.dispose]() { | ||
if (typeof this.iterableIterator.return === 'function') { | ||
this.iterableIterator.return(); | ||
} | ||
[DisposableSymbols.dispose]() { | ||
this.iterableIterator.return?.(); | ||
} | ||
@@ -116,0 +115,0 @@ next(...[value]) { |
@@ -65,2 +65,17 @@ import { Readable } from 'stream'; | ||
let ongoing = false; | ||
const readImpl = async (desiredSize) => { | ||
if (!started) { | ||
const controller = createController(desiredSize, this.readable); | ||
started = true; | ||
await underlyingSource?.start?.(controller); | ||
controller._flush(); | ||
if (controller._closed) { | ||
return; | ||
} | ||
} | ||
const controller = createController(desiredSize, this.readable); | ||
await underlyingSource?.pull?.(controller); | ||
controller._flush(); | ||
ongoing = false; | ||
}; | ||
this.readable = new Readable({ | ||
@@ -72,17 +87,3 @@ read(desiredSize) { | ||
ongoing = true; | ||
return Promise.resolve().then(async () => { | ||
if (!started) { | ||
const controller = createController(desiredSize, this); | ||
started = true; | ||
await underlyingSource?.start?.(controller); | ||
controller._flush(); | ||
if (controller._closed) { | ||
return; | ||
} | ||
} | ||
const controller = createController(desiredSize, this); | ||
await underlyingSource?.pull?.(controller); | ||
controller._flush(); | ||
ongoing = false; | ||
}); | ||
return readImpl(desiredSize); | ||
}, | ||
@@ -159,2 +160,13 @@ destroy(err, callback) { | ||
} | ||
async pipeToWriter(writer) { | ||
try { | ||
for await (const chunk of this) { | ||
await writer.write(chunk); | ||
} | ||
await writer.close(); | ||
} | ||
catch (err) { | ||
await writer.abort(err); | ||
} | ||
} | ||
pipeTo(destination) { | ||
@@ -170,13 +182,3 @@ if (isPonyfillWritableStream(destination)) { | ||
const writer = destination.getWriter(); | ||
return Promise.resolve().then(async () => { | ||
try { | ||
for await (const chunk of this) { | ||
await writer.write(chunk); | ||
} | ||
await writer.close(); | ||
} | ||
catch (err) { | ||
await writer.abort(err); | ||
} | ||
}); | ||
return this.pipeToWriter(writer); | ||
} | ||
@@ -183,0 +185,0 @@ } |
@@ -5,2 +5,3 @@ import { Agent as HTTPAgent } from 'http'; | ||
import { isHeadersLike, PonyfillHeaders } from './Headers.js'; | ||
import { PonyfillURL } from './URL.js'; | ||
function isRequest(input) { | ||
@@ -14,13 +15,22 @@ return input[Symbol.toStringTag] === 'Request'; | ||
constructor(input, options) { | ||
let url; | ||
let _url; | ||
let _parsedUrl; | ||
let bodyInit = null; | ||
let requestInit; | ||
if (typeof input === 'string') { | ||
url = input; | ||
_url = input; | ||
} | ||
else if (isURL(input)) { | ||
url = input.toString(); | ||
_parsedUrl = input; | ||
} | ||
else if (isRequest(input)) { | ||
url = input.url; | ||
if (input._parsedUrl) { | ||
_parsedUrl = input._parsedUrl; | ||
} | ||
else if (input._url) { | ||
_url = input._url; | ||
} | ||
else { | ||
_url = input.url; | ||
} | ||
bodyInit = input.body; | ||
@@ -34,2 +44,4 @@ requestInit = input; | ||
super(bodyInit, options); | ||
this._url = _url; | ||
this._parsedUrl = _parsedUrl; | ||
this.cache = requestInit?.cache || 'default'; | ||
@@ -51,3 +63,2 @@ this.credentials = requestInit?.credentials || 'same-origin'; | ||
this.duplex = requestInit?.duplex || 'half'; | ||
this.url = url || ''; | ||
this.destination = 'document'; | ||
@@ -59,9 +70,10 @@ this.priority = 'auto'; | ||
if (requestInit?.agent != null) { | ||
const protocol = _parsedUrl?.protocol || _url || this.url; | ||
if (requestInit.agent === false) { | ||
this.agent = false; | ||
} | ||
else if (this.url.startsWith('http:/') && requestInit.agent instanceof HTTPAgent) { | ||
else if (protocol.startsWith('http:') && requestInit.agent instanceof HTTPAgent) { | ||
this.agent = requestInit.agent; | ||
} | ||
else if (this.url.startsWith('https:/') && requestInit.agent instanceof HTTPSAgent) { | ||
else if (protocol.startsWith('https:') && requestInit.agent instanceof HTTPSAgent) { | ||
this.agent = requestInit.agent; | ||
@@ -84,3 +96,26 @@ } | ||
referrerPolicy; | ||
url; | ||
_url; | ||
get url() { | ||
if (this._url == null) { | ||
if (this._parsedUrl) { | ||
this._url = this._parsedUrl.toString(); | ||
} | ||
else { | ||
throw new TypeError('Invalid URL'); | ||
} | ||
} | ||
return this._url; | ||
} | ||
_parsedUrl; | ||
get parsedUrl() { | ||
if (this._parsedUrl == null) { | ||
if (this._url != null) { | ||
this._parsedUrl = new PonyfillURL(this._url); | ||
} | ||
else { | ||
throw new TypeError('Invalid URL'); | ||
} | ||
} | ||
return this._parsedUrl; | ||
} | ||
duplex; | ||
@@ -87,0 +122,0 @@ agent; |
@@ -68,2 +68,3 @@ import { resolveObjectURL } from 'buffer'; | ||
} | ||
[Symbol.toStringTag] = 'URL'; | ||
} |
@@ -8,7 +8,3 @@ function isHeadersInstance(obj) { | ||
} | ||
const obj = {}; | ||
headers.forEach((value, key) => { | ||
obj[key] = value; | ||
}); | ||
return obj; | ||
return Object.fromEntries(headers.entries()); | ||
} | ||
@@ -15,0 +11,0 @@ export function defaultHeadersSerializer(headers, onContentLength) { |
{ | ||
"name": "@whatwg-node/node-fetch", | ||
"version": "0.7.3", | ||
"version": "0.7.4-alpha-20241125124758-22623cd8c312a8c35092a436e5a2c631dd52f59d", | ||
"description": "Fetch API implementation for Node", | ||
@@ -8,2 +8,3 @@ "sideEffects": false, | ||
"@kamilkisiela/fast-url-parser": "^1.1.4", | ||
"@whatwg-node/disposablestack": "^0.0.5", | ||
"busboy": "^1.6.0", | ||
@@ -10,0 +11,0 @@ "fast-querystring": "^1.1.1", |
@@ -0,1 +1,2 @@ | ||
import { DisposableSymbols } from '@whatwg-node/disposablestack'; | ||
export declare class PonyfillIteratorObject<T> implements IteratorObject<T, undefined, unknown> { | ||
@@ -16,5 +17,5 @@ private iterableIterator; | ||
toArray(): T[]; | ||
[Symbol.dispose](): void; | ||
[DisposableSymbols.dispose](): void; | ||
next(...[value]: [] | [unknown]): IteratorResult<T, undefined>; | ||
[Symbol.iterator](): URLSearchParamsIterator<T>; | ||
} |
@@ -13,2 +13,3 @@ import { Readable } from 'stream'; | ||
tee(): [ReadableStream<T>, ReadableStream<T>]; | ||
private pipeToWriter; | ||
pipeTo(destination: WritableStream<T>): Promise<void>; | ||
@@ -15,0 +16,0 @@ pipeThrough<T2>({ writable, readable, }: { |
@@ -28,3 +28,6 @@ import { Agent as HTTPAgent } from 'http'; | ||
referrerPolicy: ReferrerPolicy; | ||
url: string; | ||
_url: string | undefined; | ||
get url(): string; | ||
_parsedUrl: URL | undefined; | ||
get parsedUrl(): URL; | ||
duplex: 'half' | 'full'; | ||
@@ -31,0 +34,0 @@ agent: HTTPAgent | HTTPSAgent | false | undefined; |
@@ -19,2 +19,3 @@ import FastUrl from '@kamilkisiela/fast-url-parser'; | ||
static getBlobFromURL(url: string): Blob | PonyfillBlob | undefined; | ||
[Symbol.toStringTag]: string; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
229830
5925
5
+ Added@whatwg-node/disposablestack@0.0.5(transitive)