code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function buildHeaders(headers) { if (Array.isArray(headers)) { const headersPair = {}; for (let i = 0; i < headers.length; i += 2) { headersPair[headers[i]] = headers[i + 1]; } return headersPair; } return headers; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
buildHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function throwIfProxyAuthIsSent(headers) { const existProxyAuth = headers && Object.keys(headers).find((key) => key.toLowerCase() === "proxy-authorization"); if (existProxyAuth) { throw new InvalidArgumentError("Proxy-Authorization should be sent in ProxyAgent constructor"); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
throwIfProxyAuthIsSent
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor(opts = {}) { super(); __privateAdd(this, _getProxyAgentForUrl); __privateAdd(this, _shouldProxy); __privateAdd(this, _parseNoProxy); __privateAdd(this, _noProxyChanged); __privateAdd(this, _noProxyEnv); __privateAdd(this, _noProxyValue, null); __privateAdd(this, _noProxyEntries, null); __privateAdd(this, _opts, null); __privateSet(this, _opts, opts); if (!experimentalWarned) { experimentalWarned = true; define_process_default.emitWarning("EnvHttpProxyAgent is experimental, expect them to change at any time.", { code: "UNDICI-EHPA" }); } const { httpProxy, httpsProxy, noProxy, ...agentOpts } = opts; this[kNoProxyAgent] = new Agent(agentOpts); const HTTP_PROXY = httpProxy ?? define_process_default.env.http_proxy ?? define_process_default.env.HTTP_PROXY; if (HTTP_PROXY) { this[kHttpProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTP_PROXY }); } else { this[kHttpProxyAgent] = this[kNoProxyAgent]; } const HTTPS_PROXY = httpsProxy ?? define_process_default.env.https_proxy ?? define_process_default.env.HTTPS_PROXY; if (HTTPS_PROXY) { this[kHttpsProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTPS_PROXY }); } else { this[kHttpsProxyAgent] = this[kHttpProxyAgent]; } __privateMethod(this, _parseNoProxy, parseNoProxy_fn).call(this); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function calculateRetryAfterHeader(retryAfter) { const current = Date.now(); return new Date(retryAfter).getTime() - current; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
calculateRetryAfterHeader
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor(opts, handlers) { const { retryOptions, ...dispatchOpts } = opts; const { // Retry scoped retry: retryFn, maxRetries, maxTimeout, minTimeout, timeoutFactor, // Response scoped methods, errorCodes, retryAfter, statusCodes } = retryOptions ?? {}; this.dispatch = handlers.dispatch; this.handler = handlers.handler; this.opts = { ...dispatchOpts, body: wrapRequestBody(opts.body) }; this.abort = null; this.aborted = false; this.retryOpts = { retry: retryFn ?? _RetryHandler[kRetryHandlerDefaultRetry], retryAfter: retryAfter ?? true, maxTimeout: maxTimeout ?? 30 * 1e3, // 30s, minTimeout: minTimeout ?? 500, // .5s timeoutFactor: timeoutFactor ?? 2, maxRetries: maxRetries ?? 5, // What errors we should retry methods: methods ?? ["GET", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE"], // Indicates which errors to retry statusCodes: statusCodes ?? [500, 502, 503, 504, 429], // List of errors to retry errorCodes: errorCodes ?? [ "ECONNRESET", "ECONNREFUSED", "ENOTFOUND", "ENETDOWN", "ENETUNREACH", "EHOSTDOWN", "EHOSTUNREACH", "EPIPE", "UND_ERR_SOCKET" ] }; this.retryCount = 0; this.retryCountCheckpoint = 0; this.start = 0; this.end = null; this.etag = null; this.resume = null; this.handler.onConnect((reason) => { this.aborted = true; if (this.abort) { this.abort(reason); } else { this.reason = reason; } }); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onRequestSent() { if (this.handler.onRequestSent) { this.handler.onRequestSent(); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onRequestSent
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onUpgrade(statusCode, headers, socket) { if (this.handler.onUpgrade) { this.handler.onUpgrade(statusCode, headers, socket); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onUpgrade
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onConnect(abort) { if (this.aborted) { abort(this.reason); } else { this.abort = abort; } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onBodySent(chunk) { if (this.handler.onBodySent) return this.handler.onBodySent(chunk); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onBodySent
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onHeaders(statusCode, rawHeaders, resume, statusMessage) { const headers = parseHeaders(rawHeaders); this.retryCount += 1; if (statusCode >= 300) { if (this.retryOpts.statusCodes.includes(statusCode) === false) { return this.handler.onHeaders( statusCode, rawHeaders, resume, statusMessage ); } else { this.abort( new RequestRetryError("Request failed", statusCode, { headers, data: { count: this.retryCount } }) ); return false; } } if (this.resume != null) { this.resume = null; if (statusCode !== 206 && (this.start > 0 || statusCode !== 200)) { this.abort( new RequestRetryError("server does not support the range header and the payload was partially consumed", statusCode, { headers, data: { count: this.retryCount } }) ); return false; } const contentRange = parseRangeHeader(headers["content-range"]); if (!contentRange) { this.abort( new RequestRetryError("Content-Range mismatch", statusCode, { headers, data: { count: this.retryCount } }) ); return false; } if (this.etag != null && this.etag !== headers.etag) { this.abort( new RequestRetryError("ETag mismatch", statusCode, { headers, data: { count: this.retryCount } }) ); return false; } const { start, size, end = size - 1 } = contentRange; assert(this.start === start, "content-range mismatch"); assert(this.end == null || this.end === end, "content-range mismatch"); this.resume = resume; return true; } if (this.end == null) { if (statusCode === 206) { const range = parseRangeHeader(headers["content-range"]); if (range == null) { return this.handler.onHeaders( statusCode, rawHeaders, resume, statusMessage ); } const { start, size, end = size - 1 } = range; assert( start != null && Number.isFinite(start), "content-range mismatch" ); assert(end != null && Number.isFinite(end), "invalid content-length"); this.start = start; this.end = end; } if (this.end == null) { const contentLength = headers["content-length"]; this.end = contentLength != null ? Number(contentLength) - 1 : null; } assert(Number.isFinite(this.start)); assert( this.end == null || Number.isFinite(this.end), "invalid content-length" ); this.resume = resume; this.etag = headers.etag != null ? headers.etag : null; if (this.etag != null && this.etag.startsWith("W/")) { this.etag = null; } return this.handler.onHeaders( statusCode, rawHeaders, resume, statusMessage ); } const err = new RequestRetryError("Request failed", statusCode, { headers, data: { count: this.retryCount } }); this.abort(err); return false; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onData(chunk) { this.start += chunk.length; return this.handler.onData(chunk); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onComplete(rawTrailers) { this.retryCount = 0; return this.handler.onComplete(rawTrailers); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onComplete
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onError(err) { if (this.aborted || isDisturbed(this.opts.body)) { return this.handler.onError(err); } if (this.retryCount - this.retryCountCheckpoint > 0) { this.retryCount = this.retryCountCheckpoint + (this.retryCount - this.retryCountCheckpoint); } else { this.retryCount += 1; } this.retryOpts.retry( err, { state: { counter: this.retryCount }, opts: { retryOptions: this.retryOpts, ...this.opts } }, onRetry.bind(this) ); function onRetry(err2) { if (err2 != null || this.aborted || isDisturbed(this.opts.body)) { return this.handler.onError(err2); } if (this.start !== 0) { const headers = { range: `bytes=${this.start}-${this.end ?? ""}` }; if (this.etag != null) { headers["if-match"] = this.etag; } this.opts = { ...this.opts, headers: { ...this.opts.headers, ...headers } }; } try { this.retryCountCheckpoint = this.retryCount; this.dispatch(this.opts, this); } catch (err3) { this.handler.onError(err3); } } __name(onRetry, "onRetry"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function onRetry(err2) { if (err2 != null || this.aborted || isDisturbed(this.opts.body)) { return this.handler.onError(err2); } if (this.start !== 0) { const headers = { range: `bytes=${this.start}-${this.end ?? ""}` }; if (this.etag != null) { headers["if-match"] = this.etag; } this.opts = { ...this.opts, headers: { ...this.opts.headers, ...headers } }; } try { this.retryCountCheckpoint = this.retryCount; this.dispatch(this.opts, this); } catch (err3) { this.handler.onError(err3); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onRetry
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor(agent, options = {}) { super(options); __privateAdd(this, _agent, null); __privateAdd(this, _options, null); __privateSet(this, _agent, agent); __privateSet(this, _options, options); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
dispatch(opts, handler) { const retry = new RetryHandler({ ...opts, retryOptions: __privateGet(this, _options) }, { dispatch: __privateGet(this, _agent).dispatch.bind(__privateGet(this, _agent)), handler }); return __privateGet(this, _agent).dispatch(opts, retry); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
dispatch
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
close() { return __privateGet(this, _agent).close(); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
close
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
destroy() { return __privateGet(this, _agent).destroy(); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
destroy
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor({ resume, abort, contentType = "", contentLength, highWaterMark = 64 * 1024 // Same as nodejs fs streams. }) { super({ autoDestroy: true, read: resume, highWaterMark }); this._readableState.dataEmitted = false; this[kAbort] = abort; this[kConsume] = null; this[kBody] = null; this[kContentType] = contentType; this[kContentLength] = contentLength; this[kReading] = false; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
destroy(err) { if (!err && !this._readableState.endEmitted) { err = new RequestAbortedError(); } if (err) { this[kAbort](); } return super.destroy(err); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
destroy
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
_destroy(err, callback) { if (!this[kReading]) { setImmediate(() => { callback(err); }); } else { callback(err); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
_destroy
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
on(ev, ...args) { if (ev === "data" || ev === "readable") { this[kReading] = true; } return super.on(ev, ...args); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
on
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
addListener(ev, ...args) { return this.on(ev, ...args); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
addListener
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
off(ev, ...args) { const ret = super.off(ev, ...args); if (ev === "data" || ev === "readable") { this[kReading] = this.listenerCount("data") > 0 || this.listenerCount("readable") > 0; } return ret; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
off
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
removeListener(ev, ...args) { return this.off(ev, ...args); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
removeListener
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
push(chunk) { if (this[kConsume] && chunk !== null) { consumePush(this[kConsume], chunk); return this[kReading] ? super.push(chunk) : true; } return super.push(chunk); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
push
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
async text() { return consume(this, "text"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
text
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
async json() { return consume(this, "json"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
json
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
async blob() { return consume(this, "blob"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
blob
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
async bytes() { return consume(this, "bytes"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
bytes
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
async arrayBuffer() { return consume(this, "arrayBuffer"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
arrayBuffer
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
async formData() { throw new NotSupportedError(); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
formData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
get bodyUsed() { return util.isDisturbed(this); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
bodyUsed
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
get body() { if (!this[kBody]) { this[kBody] = ReadableStreamFrom(this); if (this[kConsume]) { this[kBody].getReader(); assert(this[kBody].locked); } } return this[kBody]; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
body
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
async dump(opts) { let limit = Number.isFinite(opts?.limit) ? opts.limit : 128 * 1024; const signal = opts?.signal; if (signal != null && (typeof signal !== "object" || !("aborted" in signal))) { throw new InvalidArgumentError("signal must be an AbortSignal"); } signal?.throwIfAborted(); if (this._readableState.closeEmitted) { return null; } return await new Promise((resolve, reject) => { if (this[kContentLength] > limit) { this.destroy(new AbortError()); } const onAbort = /* @__PURE__ */ __name(() => { this.destroy(signal.reason ?? new AbortError()); }, "onAbort"); signal?.addEventListener("abort", onAbort); this.on("close", function() { signal?.removeEventListener("abort", onAbort); if (signal?.aborted) { reject(signal.reason ?? new AbortError()); } else { resolve(null); } }).on("error", noop).on("data", function(chunk) { limit -= chunk.length; if (limit <= 0) { this.destroy(); } }).resume(); }); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
dump
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function isLocked(self) { return self[kBody] && self[kBody].locked === true || self[kConsume]; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
isLocked
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function isUnusable(self) { return util.isDisturbed(self) || isLocked(self); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
isUnusable
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
async function consume(stream, type) { assert(!stream[kConsume]); return new Promise((resolve, reject) => { if (isUnusable(stream)) { const rState = stream._readableState; if (rState.destroyed && rState.closeEmitted === false) { stream.on("error", (err) => { reject(err); }).on("close", () => { reject(new TypeError("unusable")); }); } else { reject(rState.errored ?? new TypeError("unusable")); } } else { queueMicrotask(() => { stream[kConsume] = { type, stream, resolve, reject, length: 0, body: [] }; stream.on("error", function(err) { consumeFinish(this[kConsume], err); }).on("close", function() { if (this[kConsume].body !== null) { consumeFinish(this[kConsume], new RequestAbortedError()); } }); consumeStart(stream[kConsume]); }); } }); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
consume
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function consumeStart(consume2) { if (consume2.body === null) { return; } const { _readableState: state } = consume2.stream; if (state.bufferIndex) { const start = state.bufferIndex; const end = state.buffer.length; for (let n = start; n < end; n++) { consumePush(consume2, state.buffer[n]); } } else { for (const chunk of state.buffer) { consumePush(consume2, chunk); } } if (state.endEmitted) { consumeEnd(this[kConsume]); } else { consume2.stream.on("end", function() { consumeEnd(this[kConsume]); }); } consume2.stream.resume(); while (consume2.stream.read() != null) { } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
consumeStart
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function chunksDecode(chunks, length) { if (chunks.length === 0 || length === 0) { return ""; } const buffer = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, length); const bufferLength = buffer.length; const start = bufferLength > 2 && buffer[0] === 239 && buffer[1] === 187 && buffer[2] === 191 ? 3 : 0; return buffer.utf8Slice(start, bufferLength); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
chunksDecode
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function chunksConcat(chunks, length) { if (chunks.length === 0 || length === 0) { return new Uint8Array(0); } if (chunks.length === 1) { return new Uint8Array(chunks[0]); } const buffer = new Uint8Array(Buffer.allocUnsafeSlow(length).buffer); let offset = 0; for (let i = 0; i < chunks.length; ++i) { const chunk = chunks[i]; buffer.set(chunk, offset); offset += chunk.length; } return buffer; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
chunksConcat
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function consumeEnd(consume2) { const { type, body, resolve, stream, length } = consume2; try { if (type === "text") { resolve(chunksDecode(body, length)); } else if (type === "json") { resolve(JSON.parse(chunksDecode(body, length))); } else if (type === "arrayBuffer") { resolve(chunksConcat(body, length).buffer); } else if (type === "blob") { resolve(new Blob(body, { type: stream[kContentType] })); } else if (type === "bytes") { resolve(chunksConcat(body, length)); } consumeFinish(consume2); } catch (err) { stream.destroy(err); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
consumeEnd
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function consumePush(consume2, chunk) { consume2.length += chunk.length; consume2.body.push(chunk); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
consumePush
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function consumeFinish(consume2, err) { if (consume2.body === null) { return; } if (err) { consume2.reject(err); } else { consume2.resolve(); } consume2.type = null; consume2.stream = null; consume2.resolve = null; consume2.reject = null; consume2.length = 0; consume2.body = null; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
consumeFinish
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
async function getResolveErrorBodyCallback({ callback, body, contentType, statusCode, statusMessage, headers }) { assert(body); let chunks = []; let length = 0; try { for await (const chunk of body) { chunks.push(chunk); length += chunk.length; if (length > CHUNK_LIMIT) { chunks = []; length = 0; break; } } } catch { chunks = []; length = 0; } const message = `Response status code ${statusCode}${statusMessage ? `: ${statusMessage}` : ""}`; if (statusCode === 204 || !contentType || !length) { queueMicrotask(() => callback(new ResponseStatusCodeError(message, statusCode, headers))); return; } const stackTraceLimit = Error.stackTraceLimit; Error.stackTraceLimit = 0; let payload; try { if (isContentTypeApplicationJson(contentType)) { payload = JSON.parse(chunksDecode(chunks, length)); } else if (isContentTypeText(contentType)) { payload = chunksDecode(chunks, length); } } catch { } finally { Error.stackTraceLimit = stackTraceLimit; } queueMicrotask(() => callback(new ResponseStatusCodeError(message, statusCode, headers, payload))); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
getResolveErrorBodyCallback
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor(opts, callback) { if (!opts || typeof opts !== "object") { throw new InvalidArgumentError("invalid opts"); } const { signal, method, opaque, body, onInfo, responseHeaders, throwOnError, highWaterMark } = opts; try { if (typeof callback !== "function") { throw new InvalidArgumentError("invalid callback"); } if (highWaterMark && (typeof highWaterMark !== "number" || highWaterMark < 0)) { throw new InvalidArgumentError("invalid highWaterMark"); } if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") { throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget"); } if (method === "CONNECT") { throw new InvalidArgumentError("invalid method"); } if (onInfo && typeof onInfo !== "function") { throw new InvalidArgumentError("invalid onInfo callback"); } super("UNDICI_REQUEST"); } catch (err) { if (util.isStream(body)) { util.destroy(body.on("error", util.nop), err); } throw err; } this.method = method; this.responseHeaders = responseHeaders || null; this.opaque = opaque || null; this.callback = callback; this.res = null; this.abort = null; this.body = body; this.trailers = {}; this.context = null; this.onInfo = onInfo || null; this.throwOnError = throwOnError; this.highWaterMark = highWaterMark; this.signal = signal; this.reason = null; this.removeAbortListener = null; if (util.isStream(body)) { body.on("error", (err) => { this.onError(err); }); } if (this.signal) { if (this.signal.aborted) { this.reason = this.signal.reason ?? new RequestAbortedError(); } else { this.removeAbortListener = util.addAbortListener(this.signal, () => { this.reason = this.signal.reason ?? new RequestAbortedError(); if (this.res) { util.destroy(this.res, this.reason); } else if (this.abort) { this.abort(this.reason); } if (this.removeAbortListener) { this.res?.off("close", this.removeAbortListener); this.removeAbortListener(); this.removeAbortListener = null; } }); } } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onConnect(abort, context) { if (this.reason) { abort(this.reason); return; } assert(this.callback); this.abort = abort; this.context = context; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onHeaders(statusCode, rawHeaders, resume, statusMessage) { const { callback, opaque, abort, context, responseHeaders, highWaterMark } = this; const headers = responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); if (statusCode < 200) { if (this.onInfo) { this.onInfo({ statusCode, headers }); } return; } const parsedHeaders = responseHeaders === "raw" ? util.parseHeaders(rawHeaders) : headers; const contentType = parsedHeaders["content-type"]; const contentLength = parsedHeaders["content-length"]; const res = new Readable({ resume, abort, contentType, contentLength: this.method !== "HEAD" && contentLength ? Number(contentLength) : null, highWaterMark }); if (this.removeAbortListener) { res.on("close", this.removeAbortListener); } this.callback = null; this.res = res; if (callback !== null) { if (this.throwOnError && statusCode >= 400) { this.runInAsyncScope( getResolveErrorBodyCallback, null, { callback, body: res, contentType, statusCode, statusMessage, headers } ); } else { this.runInAsyncScope(callback, null, null, { statusCode, headers, trailers: this.trailers, opaque, body: res, context }); } } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onData(chunk) { return this.res.push(chunk); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onComplete(trailers) { util.parseHeaders(trailers, this.trailers); this.res.push(null); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onComplete
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onError(err) { const { res, callback, body, opaque } = this; if (callback) { this.callback = null; queueMicrotask(() => { this.runInAsyncScope(callback, null, err, { opaque }); }); } if (res) { this.res = null; queueMicrotask(() => { util.destroy(res, err); }); } if (body) { this.body = null; util.destroy(body, err); } if (this.removeAbortListener) { res?.off("close", this.removeAbortListener); this.removeAbortListener(); this.removeAbortListener = null; } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function request(opts, callback) { if (callback === void 0) { return new Promise((resolve, reject) => { request.call(this, opts, (err, data) => { return err ? reject(err) : resolve(data); }); }); } try { this.dispatch(opts, new RequestHandler(opts, callback)); } catch (err) { if (typeof callback !== "function") { throw err; } const opaque = opts?.opaque; queueMicrotask(() => callback(err, { opaque })); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
request
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function abort(self) { if (self.abort) { self.abort(self[kSignal]?.reason); } else { self.reason = self[kSignal]?.reason ?? new RequestAbortedError(); } removeSignal(self); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
abort
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function addSignal(self, signal) { self.reason = null; self[kSignal] = null; self[kListener] = null; if (!signal) { return; } if (signal.aborted) { abort(self); return; } self[kSignal] = signal; self[kListener] = () => { abort(self); }; addAbortListener(self[kSignal], self[kListener]); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
addSignal
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function removeSignal(self) { if (!self[kSignal]) { return; } if ("removeEventListener" in self[kSignal]) { self[kSignal].removeEventListener("abort", self[kListener]); } else { self[kSignal].removeListener("abort", self[kListener]); } self[kSignal] = null; self[kListener] = null; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
removeSignal
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor(opts, factory, callback) { if (!opts || typeof opts !== "object") { throw new InvalidArgumentError("invalid opts"); } const { signal, method, opaque, body, onInfo, responseHeaders, throwOnError } = opts; try { if (typeof callback !== "function") { throw new InvalidArgumentError("invalid callback"); } if (typeof factory !== "function") { throw new InvalidArgumentError("invalid factory"); } if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") { throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget"); } if (method === "CONNECT") { throw new InvalidArgumentError("invalid method"); } if (onInfo && typeof onInfo !== "function") { throw new InvalidArgumentError("invalid onInfo callback"); } super("UNDICI_STREAM"); } catch (err) { if (util.isStream(body)) { util.destroy(body.on("error", util.nop), err); } throw err; } this.responseHeaders = responseHeaders || null; this.opaque = opaque || null; this.factory = factory; this.callback = callback; this.res = null; this.abort = null; this.context = null; this.trailers = null; this.body = body; this.onInfo = onInfo || null; this.throwOnError = throwOnError || false; if (util.isStream(body)) { body.on("error", (err) => { this.onError(err); }); } addSignal(this, signal); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onConnect(abort, context) { if (this.reason) { abort(this.reason); return; } assert(this.callback); this.abort = abort; this.context = context; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onHeaders(statusCode, rawHeaders, resume, statusMessage) { const { factory, opaque, context, callback, responseHeaders } = this; const headers = responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); if (statusCode < 200) { if (this.onInfo) { this.onInfo({ statusCode, headers }); } return; } this.factory = null; let res; if (this.throwOnError && statusCode >= 400) { const parsedHeaders = responseHeaders === "raw" ? util.parseHeaders(rawHeaders) : headers; const contentType = parsedHeaders["content-type"]; res = new PassThrough(); this.callback = null; this.runInAsyncScope( getResolveErrorBodyCallback, null, { callback, body: res, contentType, statusCode, statusMessage, headers } ); } else { if (factory === null) { return; } res = this.runInAsyncScope(factory, null, { statusCode, headers, opaque, context }); if (!res || typeof res.write !== "function" || typeof res.end !== "function" || typeof res.on !== "function") { throw new InvalidReturnValueError("expected Writable"); } finished(res, { readable: false }, (err) => { const { callback: callback2, res: res2, opaque: opaque2, trailers, abort } = this; this.res = null; if (err || !res2.readable) { util.destroy(res2, err); } this.callback = null; this.runInAsyncScope(callback2, null, err || null, { opaque: opaque2, trailers }); if (err) { abort(); } }); } res.on("drain", resume); this.res = res; const needDrain = res.writableNeedDrain !== void 0 ? res.writableNeedDrain : res._writableState?.needDrain; return needDrain !== true; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onData(chunk) { const { res } = this; return res ? res.write(chunk) : true; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onComplete(trailers) { const { res } = this; removeSignal(this); if (!res) { return; } this.trailers = util.parseHeaders(trailers); res.end(); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onComplete
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onError(err) { const { res, callback, opaque, body } = this; removeSignal(this); this.factory = null; if (res) { this.res = null; util.destroy(res, err); } else if (callback) { this.callback = null; queueMicrotask(() => { this.runInAsyncScope(callback, null, err, { opaque }); }); } if (body) { this.body = null; util.destroy(body, err); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function stream(opts, factory, callback) { if (callback === void 0) { return new Promise((resolve, reject) => { stream.call(this, opts, factory, (err, data) => { return err ? reject(err) : resolve(data); }); }); } try { this.dispatch(opts, new StreamHandler(opts, factory, callback)); } catch (err) { if (typeof callback !== "function") { throw err; } const opaque = opts?.opaque; queueMicrotask(() => callback(err, { opaque })); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
stream
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor() { super({ autoDestroy: true }); this[kResume] = null; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
_read() { const { [kResume]: resume } = this; if (resume) { this[kResume] = null; resume(); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
_read
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
_destroy(err, callback) { this._read(); callback(err); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
_destroy
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor(resume) { super({ autoDestroy: true }); this[kResume] = resume; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
_destroy(err, callback) { if (!err && !this._readableState.endEmitted) { err = new RequestAbortedError(); } callback(err); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
_destroy
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor(opts, handler) { if (!opts || typeof opts !== "object") { throw new InvalidArgumentError("invalid opts"); } if (typeof handler !== "function") { throw new InvalidArgumentError("invalid handler"); } const { signal, method, opaque, onInfo, responseHeaders } = opts; if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") { throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget"); } if (method === "CONNECT") { throw new InvalidArgumentError("invalid method"); } if (onInfo && typeof onInfo !== "function") { throw new InvalidArgumentError("invalid onInfo callback"); } super("UNDICI_PIPELINE"); this.opaque = opaque || null; this.responseHeaders = responseHeaders || null; this.handler = handler; this.abort = null; this.context = null; this.onInfo = onInfo || null; this.req = new PipelineRequest().on("error", util.nop); this.ret = new Duplex({ readableObjectMode: opts.objectMode, autoDestroy: true, read: () => { const { body } = this; if (body?.resume) { body.resume(); } }, write: (chunk, encoding, callback) => { const { req } = this; if (req.push(chunk, encoding) || req._readableState.destroyed) { callback(); } else { req[kResume] = callback; } }, destroy: (err, callback) => { const { body, req, res, ret, abort } = this; if (!err && !ret._readableState.endEmitted) { err = new RequestAbortedError(); } if (abort && err) { abort(); } util.destroy(body, err); util.destroy(req, err); util.destroy(res, err); removeSignal(this); callback(err); } }).on("prefinish", () => { const { req } = this; req.push(null); }); this.res = null; addSignal(this, signal); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onConnect(abort, context) { const { ret, res } = this; if (this.reason) { abort(this.reason); return; } assert(!res, "pipeline cannot be retried"); assert(!ret.destroyed); this.abort = abort; this.context = context; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onHeaders(statusCode, rawHeaders, resume) { const { opaque, handler, context } = this; if (statusCode < 200) { if (this.onInfo) { const headers = this.responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); this.onInfo({ statusCode, headers }); } return; } this.res = new PipelineResponse(resume); let body; try { this.handler = null; const headers = this.responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); body = this.runInAsyncScope(handler, null, { statusCode, headers, opaque, body: this.res, context }); } catch (err) { this.res.on("error", util.nop); throw err; } if (!body || typeof body.on !== "function") { throw new InvalidReturnValueError("expected Readable"); } body.on("data", (chunk) => { const { ret, body: body2 } = this; if (!ret.push(chunk) && body2.pause) { body2.pause(); } }).on("error", (err) => { const { ret } = this; util.destroy(ret, err); }).on("end", () => { const { ret } = this; ret.push(null); }).on("close", () => { const { ret } = this; if (!ret._readableState.ended) { util.destroy(ret, new RequestAbortedError()); } }); this.body = body; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onData(chunk) { const { res } = this; return res.push(chunk); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onComplete(trailers) { const { res } = this; res.push(null); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onComplete
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onError(err) { const { ret } = this; this.handler = null; util.destroy(ret, err); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function pipeline(opts, handler) { try { const pipelineHandler = new PipelineHandler(opts, handler); this.dispatch({ ...opts, body: pipelineHandler.req }, pipelineHandler); return pipelineHandler.ret; } catch (err) { return new PassThrough().destroy(err); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
pipeline
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor(opts, callback) { if (!opts || typeof opts !== "object") { throw new InvalidArgumentError("invalid opts"); } if (typeof callback !== "function") { throw new InvalidArgumentError("invalid callback"); } const { signal, opaque, responseHeaders } = opts; if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") { throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget"); } super("UNDICI_UPGRADE"); this.responseHeaders = responseHeaders || null; this.opaque = opaque || null; this.callback = callback; this.abort = null; this.context = null; addSignal(this, signal); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onConnect(abort, context) { if (this.reason) { abort(this.reason); return; } assert(this.callback); this.abort = abort; this.context = null; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onHeaders() { throw new SocketError("bad upgrade", null); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onUpgrade(statusCode, rawHeaders, socket) { assert(statusCode === 101); const { callback, opaque, context } = this; removeSignal(this); this.callback = null; const headers = this.responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); this.runInAsyncScope(callback, null, null, { headers, socket, opaque, context }); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onUpgrade
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onError(err) { const { callback, opaque } = this; removeSignal(this); if (callback) { this.callback = null; queueMicrotask(() => { this.runInAsyncScope(callback, null, err, { opaque }); }); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function upgrade(opts, callback) { if (callback === void 0) { return new Promise((resolve, reject) => { upgrade.call(this, opts, (err, data) => { return err ? reject(err) : resolve(data); }); }); } try { const upgradeHandler = new UpgradeHandler(opts, callback); this.dispatch({ ...opts, method: opts.method || "GET", upgrade: opts.protocol || "Websocket" }, upgradeHandler); } catch (err) { if (typeof callback !== "function") { throw err; } const opaque = opts?.opaque; queueMicrotask(() => callback(err, { opaque })); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
upgrade
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor(opts, callback) { if (!opts || typeof opts !== "object") { throw new InvalidArgumentError("invalid opts"); } if (typeof callback !== "function") { throw new InvalidArgumentError("invalid callback"); } const { signal, opaque, responseHeaders } = opts; if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") { throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget"); } super("UNDICI_CONNECT"); this.opaque = opaque || null; this.responseHeaders = responseHeaders || null; this.callback = callback; this.abort = null; addSignal(this, signal); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onConnect(abort, context) { if (this.reason) { abort(this.reason); return; } assert(this.callback); this.abort = abort; this.context = context; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onConnect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onHeaders() { throw new SocketError("bad connect", null); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onUpgrade(statusCode, rawHeaders, socket) { const { callback, opaque, context } = this; removeSignal(this); this.callback = null; let headers = rawHeaders; if (headers != null) { headers = this.responseHeaders === "raw" ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders); } this.runInAsyncScope(callback, null, null, { statusCode, headers, socket, opaque, context }); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onUpgrade
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
onError(err) { const { callback, opaque } = this; removeSignal(this); if (callback) { this.callback = null; queueMicrotask(() => { this.runInAsyncScope(callback, null, err, { opaque }); }); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
onError
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function connect(opts, callback) { if (callback === void 0) { return new Promise((resolve, reject) => { connect.call(this, opts, (err, data) => { return err ? reject(err) : resolve(data); }); }); } try { const connectHandler = new ConnectHandler(opts, callback); this.dispatch({ ...opts, method: "CONNECT" }, connectHandler); } catch (err) { if (typeof callback !== "function") { throw err; } const opaque = opts?.opaque; queueMicrotask(() => callback(err, { opaque })); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
connect
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
constructor(message) { super(message); Error.captureStackTrace(this, _MockNotMatchedError); this.name = "MockNotMatchedError"; this.message = message || "The request does not match any registered mock dispatches"; this.code = "UND_MOCK_ERR_MOCK_NOT_MATCHED"; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
constructor
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function matchValue(match, value) { if (typeof match === "string") { return match === value; } if (match instanceof RegExp) { return match.test(value); } if (typeof match === "function") { return match(value) === true; } return false; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
matchValue
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function lowerCaseEntries(headers) { return Object.fromEntries( Object.entries(headers).map(([headerName, headerValue]) => { return [headerName.toLocaleLowerCase(), headerValue]; }) ); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
lowerCaseEntries
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function getHeaderByName(headers, key) { if (Array.isArray(headers)) { for (let i = 0; i < headers.length; i += 2) { if (headers[i].toLocaleLowerCase() === key.toLocaleLowerCase()) { return headers[i + 1]; } } return void 0; } else if (typeof headers.get === "function") { return headers.get(key); } else { return lowerCaseEntries(headers)[key.toLocaleLowerCase()]; } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
getHeaderByName
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function buildHeadersFromArray(headers) { const clone = headers.slice(); const entries = []; for (let index = 0; index < clone.length; index += 2) { entries.push([clone[index], clone[index + 1]]); } return Object.fromEntries(entries); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
buildHeadersFromArray
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function matchHeaders(mockDispatch2, headers) { if (typeof mockDispatch2.headers === "function") { if (Array.isArray(headers)) { headers = buildHeadersFromArray(headers); } return mockDispatch2.headers(headers ? lowerCaseEntries(headers) : {}); } if (typeof mockDispatch2.headers === "undefined") { return true; } if (typeof headers !== "object" || typeof mockDispatch2.headers !== "object") { return false; } for (const [matchHeaderName, matchHeaderValue] of Object.entries(mockDispatch2.headers)) { const headerValue = getHeaderByName(headers, matchHeaderName); if (!matchValue(matchHeaderValue, headerValue)) { return false; } } return true; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
matchHeaders
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function safeUrl(path) { if (typeof path !== "string") { return path; } const pathSegments = path.split("?"); if (pathSegments.length !== 2) { return path; } const qp = new URLSearchParams(pathSegments.pop()); qp.sort(); return [...pathSegments, qp.toString()].join("?"); }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
safeUrl
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function matchKey(mockDispatch2, { path, method, body, headers }) { const pathMatch = matchValue(mockDispatch2.path, path); const methodMatch = matchValue(mockDispatch2.method, method); const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true; const headersMatch = matchHeaders(mockDispatch2, headers); return pathMatch && methodMatch && bodyMatch && headersMatch; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
matchKey
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function getResponseData(data) { if (Buffer.isBuffer(data)) { return data; } else if (data instanceof Uint8Array) { return data; } else if (data instanceof ArrayBuffer) { return data; } else if (typeof data === "object") { return JSON.stringify(data); } else { return data.toString(); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
getResponseData
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function getMockDispatch(mockDispatches, key) { const basePath = key.query ? buildURL(key.path, key.query) : key.path; const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath; let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path }) => matchValue(safeUrl(path), resolvedPath)); if (matchedMockDispatches.length === 0) { throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`); } matchedMockDispatches = matchedMockDispatches.filter(({ method }) => matchValue(method, key.method)); if (matchedMockDispatches.length === 0) { throw new MockNotMatchedError(`Mock dispatch not matched for method '${key.method}' on path '${resolvedPath}'`); } matchedMockDispatches = matchedMockDispatches.filter(({ body }) => typeof body !== "undefined" ? matchValue(body, key.body) : true); if (matchedMockDispatches.length === 0) { throw new MockNotMatchedError(`Mock dispatch not matched for body '${key.body}' on path '${resolvedPath}'`); } matchedMockDispatches = matchedMockDispatches.filter((mockDispatch2) => matchHeaders(mockDispatch2, key.headers)); if (matchedMockDispatches.length === 0) { const headers = typeof key.headers === "object" ? JSON.stringify(key.headers) : key.headers; throw new MockNotMatchedError(`Mock dispatch not matched for headers '${headers}' on path '${resolvedPath}'`); } return matchedMockDispatches[0]; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
getMockDispatch
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function addMockDispatch(mockDispatches, key, data) { const baseData = { timesInvoked: 0, times: 1, persist: false, consumed: false }; const replyData = typeof data === "function" ? { callback: data } : { ...data }; const newMockDispatch = { ...baseData, ...key, pending: true, data: { error: null, ...replyData } }; mockDispatches.push(newMockDispatch); return newMockDispatch; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
addMockDispatch
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function deleteMockDispatch(mockDispatches, key) { const index = mockDispatches.findIndex((dispatch) => { if (!dispatch.consumed) { return false; } return matchKey(dispatch, key); }); if (index !== -1) { mockDispatches.splice(index, 1); } }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
deleteMockDispatch
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function buildKey(opts) { const { path, method, body, headers, query } = opts; return { path, method, body, headers, query }; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
buildKey
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT
function generateKeyValues(data) { const keys = Object.keys(data); const result = []; for (let i = 0; i < keys.length; ++i) { const key = keys[i]; const value = data[key]; const name = Buffer.from(`${key}`); if (Array.isArray(value)) { for (let j = 0; j < value.length; ++j) { result.push(name, Buffer.from(`${value[j]}`)); } } else { result.push(name, Buffer.from(`${value}`)); } } return result; }
@param {import('../types/proxy-agent').ProxyAgent.Options | string | URL} opts @returns {URL}
generateKeyValues
javascript
vercel/next.js
packages/next/src/compiled/@edge-runtime/primitives/fetch.js
https://github.com/vercel/next.js/blob/master/packages/next/src/compiled/@edge-runtime/primitives/fetch.js
MIT