MCPcopy Create free account
hub / github.com/nodejs/node / onResponseStart

Function onResponseStart

deps/undici/undici.js:14388–14450  ·  view source on GitHub ↗
(controller, status, headers, statusText)

Source from the content-addressed store, hash-verified

14386 timingInfo.finalNetworkResponseStartTime = coarsenedSharedCurrentTime(fetchParams.crossOriginIsolatedCapability);
14387 },
14388 onResponseStart(controller, status, headers, statusText) {
14389 if (status < 200) {
14390 return;
14391 }
14392 const rawHeaders = controller?.rawHeaders ?? [];
14393 const headersList = new HeadersList();
14394 appendHeadersListFromResponseHeaders(headersList, headers, rawHeaders);
14395 const location = headersList.get("location", true);
14396 this.body = new Readable({ read: /* @__PURE__ */ __name(() => controller.resume(), "read") });
14397 const willFollow = location && request.redirect === "follow" && redirectStatusSet.has(status);
14398 const decoders = [];
14399 if (request.method !== "HEAD" && request.method !== "CONNECT" && !nullBodyStatus.includes(status) && !willFollow) {
14400 const contentEncoding = headersList.get("content-encoding", true);
14401 const codings = contentEncoding ? contentEncoding.toLowerCase().split(",") : [];
14402 const maxContentEncodings = 5;
14403 if (codings.length > maxContentEncodings) {
14404 reject(new Error(`too many content-encodings in response: ${codings.length}, maximum allowed is ${maxContentEncodings}`));
14405 return;
14406 }
14407 for (let i = codings.length - 1; i >= 0; --i) {
14408 const coding = codings[i].trim();
14409 if (coding === "x-gzip" || coding === "gzip") {
14410 decoders.push(zlib.createGunzip({
14411 // Be less strict when decoding compressed responses, since sometimes
14412 // servers send slightly invalid responses that are still accepted
14413 // by common browsers.
14414 // Always using Z_SYNC_FLUSH is what cURL does.
14415 flush: zlib.constants.Z_SYNC_FLUSH,
14416 finishFlush: zlib.constants.Z_SYNC_FLUSH
14417 }));
14418 } else if (coding === "deflate") {
14419 decoders.push(createInflate({
14420 flush: zlib.constants.Z_SYNC_FLUSH,
14421 finishFlush: zlib.constants.Z_SYNC_FLUSH
14422 }));
14423 } else if (coding === "br") {
14424 decoders.push(zlib.createBrotliDecompress({
14425 flush: zlib.constants.BROTLI_OPERATION_FLUSH,
14426 finishFlush: zlib.constants.BROTLI_OPERATION_FLUSH
14427 }));
14428 } else if (coding === "zstd") {
14429 decoders.push(zlib.createZstdDecompress({
14430 flush: zlib.constants.ZSTD_e_continue,
14431 finishFlush: zlib.constants.ZSTD_e_end
14432 }));
14433 } else {
14434 decoders.length = 0;
14435 break;
14436 }
14437 }
14438 }
14439 const onError = /* @__PURE__ */ __name((err) => this.onResponseError(controller, err), "onError");
14440 resolve({
14441 status,
14442 statusText,
14443 headersList,
14444 body: decoders.length ? pipeline(this.body, ...decoders, (err) => {
14445 if (err) {

Callers

nothing calls this directly

Calls 14

getMethod · 0.95
__nameFunction · 0.85
includesMethod · 0.80
createInflateFunction · 0.70
pipelineFunction · 0.70
resumeMethod · 0.65
hasMethod · 0.65
onResponseErrorMethod · 0.65
rejectFunction · 0.50
resolveFunction · 0.50
splitMethod · 0.45

Tested by

no test coverage detected