| 14986 | // Be less strict when decoding compressed responses, since sometimes |
| 14987 | // servers send slightly invalid responses that are still accepted |
| 14988 | // by common browsers. |
| 14989 | // Always using Z_SYNC_FLUSH is what cURL does. |
| 14990 | flush: zlib.constants.Z_SYNC_FLUSH, |
| 14991 | finishFlush: zlib.constants.Z_SYNC_FLUSH |
| 14992 | })); |
| 14993 | } else if (coding === "deflate") { |
| 14994 | decoders.push(createInflate({ |
| 14995 | flush: zlib.constants.Z_SYNC_FLUSH, |
| 14996 | finishFlush: zlib.constants.Z_SYNC_FLUSH |
| 14997 | })); |
| 14998 | } else if (coding === "br") { |
| 14999 | decoders.push(zlib.createBrotliDecompress({ |
| 15000 | flush: zlib.constants.BROTLI_OPERATION_FLUSH, |
| 15001 | finishFlush: zlib.constants.BROTLI_OPERATION_FLUSH |
| 15002 | })); |
| 15003 | } else { |
| 15004 | decoders.length = 0; |
| 15005 | break; |
| 15006 | } |
| 15007 | } |
| 15008 | } |
| 15009 | this.body = new Readable({ read: resume }); |
| 15010 | const onError = this.onError.bind(this); |
| 15011 | resolve2({ |
| 15012 | status, |
| 15013 | statusText, |
| 15014 | headersList, |
| 15015 | body: decoders.length ? pipeline(this.body, ...decoders, (err) => { |
| 15016 | if (err) { |
| 15017 | this.onError(err); |
| 15018 | } |
| 15019 | }).on("error", onError) : this.body.on("error", onError) |
| 15020 | }); |
| 15021 | return true; |
| 15022 | }, |
| 15023 | onData(chunk) { |
| 15024 | if (fetchParams.controller.dump) { |
| 15025 | return; |
| 15026 | } |
| 15027 | const bytes = chunk; |
| 15028 | timingInfo.encodedBodySize += bytes.byteLength; |
| 15029 | return this.body.push(bytes); |
| 15030 | }, |
| 15031 | onComplete() { |
| 15032 | if (this.abort) { |
| 15033 | fetchParams.controller.off("terminated", this.abort); |
| 15034 | } |
| 15035 | fetchParams.controller.ended = true; |
| 15036 | this.body.push(null); |
| 15037 | }, |
| 15038 | onError(error) { |
| 15039 | var _a2; |
| 15040 | if (this.abort) { |
| 15041 | fetchParams.controller.off("terminated", this.abort); |
| 15042 | } |
| 15043 | (_a2 = this.body) == null ? void 0 : _a2.destroy(error); |
| 15044 | fetchParams.controller.terminate(error); |
| 15045 | reject(error); |