| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -177,3 +177,4 @@ function request (opts, callback) { | |||
| 177 | 177 | } | |
| 178 | 178 | ||
| 179 | 179 | module.exports = request | |
| 180 | + module.exports.RequestHandler = RequestHandler | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -180,7 +180,7 @@ module.exports = class BodyReadable extends Readable { | |||
| 180 | 180 | this | |
| 181 | 181 | .on('close', function () { | |
| 182 | 182 | signalListenerCleanup() | |
| 183 | - if (signal?.aborted) { | ||
| 183 | + if (signal && signal.aborted) { | ||
| 184 | 184 | reject(signal.reason || Object.assign(new Error('The operation was aborted'), { name: 'AbortError' })) | |
| 185 | 185 | } else { | |
| 186 | 186 | resolve(null) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | 'use strict' | |
| 2 | 2 | ||
| 3 | 3 | module.exports = { | |
| 4 | - kConstruct: Symbol('constructable') | ||
| 4 | + kConstruct: require('../core/symbols').kConstruct | ||
| 5 | 5 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,5 +58,6 @@ module.exports = { | |||
| 58 | 58 | kHTTP1BuildRequest: Symbol('http1 build request'), | |
| 59 | 59 | kHTTP2CopyHeaders: Symbol('http2 copy headers'), | |
| 60 | 60 | kHTTPConnVersion: Symbol('http connection version'), | |
| 61 | - kRetryHandlerDefaultRetry: Symbol('retry agent default retry') | ||
| 61 | + kRetryHandlerDefaultRetry: Symbol('retry agent default retry'), | ||
| 62 | + kConstruct: Symbol('constructable') | ||
| 62 | 63 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,17 +119,14 @@ function dataURLProcessor (dataURL) { | |||
| 119 | 119 | * @param {boolean} excludeFragment | |
| 120 | 120 | */ | |
| 121 | 121 | function URLSerializer (url, excludeFragment = false) { | |
| 122 | - const href = url.href | ||
| 123 | - | ||
| 124 | 122 | if (!excludeFragment) { | |
| 125 | - return href | ||
| 123 | + return url.href | ||
| 126 | 124 | } | |
| 127 | 125 | ||
| 128 | - const hash = href.lastIndexOf('#') | ||
| 129 | - if (hash === -1) { | ||
| 130 | - return href | ||
| 131 | - } | ||
| 132 | - return href.slice(0, hash) | ||
| 126 | + const href = url.href | ||
| 127 | + const hashLength = url.hash.length | ||
| 128 | + | ||
| 129 | + return hashLength === 0 ? href : href.substring(0, href.length - hashLength) | ||
| 133 | 130 | } | |
| 134 | 131 | ||
| 135 | 132 | // https://infra.spec.whatwg.org/#collect-a-sequence-of-code-points | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | 'use strict' | |
| 4 | 4 | ||
| 5 | - const { kHeadersList } = require('../core/symbols') | ||
| 5 | + const { kHeadersList, kConstruct } = require('../core/symbols') | ||
| 6 | 6 | const { kGuard } = require('./symbols') | |
| 7 | 7 | const { kEnumerableProperty } = require('../core/util') | |
| 8 | 8 | const { | |
@@ -240,6 +240,9 @@ class HeadersList { | |||
| 240 | 240 | // https://fetch.spec.whatwg.org/#headers-class | |
| 241 | 241 | class Headers { | |
| 242 | 242 | constructor (init = undefined) { | |
| 243 | + if (init === kConstruct) { | ||
| 244 | + return | ||
| 245 | + } | ||
| 243 | 246 | this[kHeadersList] = new HeadersList() | |
| 244 | 247 | ||
| 245 | 248 | // The new Headers(init) constructor steps are: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -286,7 +286,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') { | |||
| 286 | 286 | } | |
| 287 | 287 | ||
| 288 | 288 | // 8. If response’s timing allow passed flag is not set, then: | |
| 289 | - if (!timingInfo.timingAllowPassed) { | ||
| 289 | + if (!response.timingAllowPassed) { | ||
| 290 | 290 | // 1. Set timingInfo to a the result of creating an opaque timing info for timingInfo. | |
| 291 | 291 | timingInfo = createOpaqueTimingInfo({ | |
| 292 | 292 | startTime: timingInfo.startTime | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,13 +28,12 @@ const { kHeaders, kSignal, kState, kGuard, kRealm } = require('./symbols') | |||
| 28 | 28 | const { webidl } = require('./webidl') | |
| 29 | 29 | const { getGlobalOrigin } = require('./global') | |
| 30 | 30 | const { URLSerializer } = require('./dataURL') | |
| 31 | - const { kHeadersList } = require('../core/symbols') | ||
| 31 | + const { kHeadersList, kConstruct } = require('../core/symbols') | ||
| 32 | 32 | const assert = require('assert') | |
| 33 | 33 | const { getMaxListeners, setMaxListeners, getEventListeners, defaultMaxListeners } = require('events') | |
| 34 | 34 | ||
| 35 | 35 | let TransformStream = globalThis.TransformStream | |
| 36 | 36 | ||
| 37 | - const kInit = Symbol('init') | ||
| 38 | 37 | const kAbortController = Symbol('abortController') | |
| 39 | 38 | ||
| 40 | 39 | const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => { | |
@@ -45,7 +44,7 @@ const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => { | |||
| 45 | 44 | class Request { | |
| 46 | 45 | // https://fetch.spec.whatwg.org/#dom-request | |
| 47 | 46 | constructor (input, init = {}) { | |
| 48 | - if (input === kInit) { | ||
| 47 | + if (input === kConstruct) { | ||
| 49 | 48 | return | |
| 50 | 49 | } | |
| 51 | 50 | ||
@@ -302,7 +301,7 @@ class Request { | |||
| 302 | 301 | } | |
| 303 | 302 | ||
| 304 | 303 | // 23. If init["integrity"] exists, then set request’s integrity metadata to it. | |
| 305 | - if (init.integrity !== undefined && init.integrity != null) { | ||
| 304 | + if (init.integrity != null) { | ||
| 306 | 305 | request.integrity = String(init.integrity) | |
| 307 | 306 | } | |
| 308 | 307 | ||
@@ -398,7 +397,7 @@ class Request { | |||
| 398 | 397 | // 30. Set this’s headers to a new Headers object with this’s relevant | |
| 399 | 398 | // Realm, whose header list is request’s header list and guard is | |
| 400 | 399 | // "request". | |
| 401 | - this[kHeaders] = new Headers() | ||
| 400 | + this[kHeaders] = new Headers(kConstruct) | ||
| 402 | 401 | this[kHeaders][kHeadersList] = request.headersList | |
| 403 | 402 | this[kHeaders][kGuard] = 'request' | |
| 404 | 403 | this[kHeaders][kRealm] = this[kRealm] | |
@@ -725,10 +724,10 @@ class Request { | |||
| 725 | 724 | ||
| 726 | 725 | // 3. Let clonedRequestObject be the result of creating a Request object, | |
| 727 | 726 | // given clonedRequest, this’s headers’s guard, and this’s relevant Realm. | |
| 728 | - const clonedRequestObject = new Request(kInit) | ||
| 727 | + const clonedRequestObject = new Request(kConstruct) | ||
| 729 | 728 | clonedRequestObject[kState] = clonedRequest | |
| 730 | 729 | clonedRequestObject[kRealm] = this[kRealm] | |
| 731 | - clonedRequestObject[kHeaders] = new Headers() | ||
| 730 | + clonedRequestObject[kHeaders] = new Headers(kConstruct) | ||
| 732 | 731 | clonedRequestObject[kHeaders][kHeadersList] = clonedRequest.headersList | |
| 733 | 732 | clonedRequestObject[kHeaders][kGuard] = this[kHeaders][kGuard] | |
| 734 | 733 | clonedRequestObject[kHeaders][kRealm] = this[kHeaders][kRealm] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ const { webidl } = require('./webidl') | |||
| 23 | 23 | const { FormData } = require('./formdata') | |
| 24 | 24 | const { getGlobalOrigin } = require('./global') | |
| 25 | 25 | const { URLSerializer } = require('./dataURL') | |
| 26 | - const { kHeadersList } = require('../core/symbols') | ||
| 26 | + const { kHeadersList, kConstruct } = require('../core/symbols') | ||
| 27 | 27 | const assert = require('assert') | |
| 28 | 28 | const { types } = require('util') | |
| 29 | 29 | ||
@@ -144,7 +144,7 @@ class Response { | |||
| 144 | 144 | // 2. Set this’s headers to a new Headers object with this’s relevant | |
| 145 | 145 | // Realm, whose header list is this’s response’s header list and guard | |
| 146 | 146 | // is "response". | |
| 147 | - this[kHeaders] = new Headers() | ||
| 147 | + this[kHeaders] = new Headers(kConstruct) | ||
| 148 | 148 | this[kHeaders][kGuard] = 'response' | |
| 149 | 149 | this[kHeaders][kHeadersList] = this[kState].headersList | |
| 150 | 150 | this[kHeaders][kRealm] = this[kRealm] | |
@@ -514,11 +514,7 @@ webidl.converters.XMLHttpRequestBodyInit = function (V) { | |||
| 514 | 514 | return webidl.converters.Blob(V, { strict: false }) | |
| 515 | 515 | } | |
| 516 | 516 | ||
| 517 | - if ( | ||
| 518 | - types.isAnyArrayBuffer(V) || | ||
| 519 | - types.isTypedArray(V) || | ||
| 520 | - types.isDataView(V) | ||
| 521 | - ) { | ||
| 517 | + if (types.isArrayBuffer(V) || types.isTypedArray(V) || types.isDataView(V)) { | ||
| 522 | 518 | return webidl.converters.BufferSource(V) | |
| 523 | 519 | } | |
| 524 | 520 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - const assert = require('node:assert') | ||
| 1 | + const assert = require('assert') | ||
| 2 | 2 | ||
| 3 | 3 | const { kRetryHandlerDefaultRetry } = require('../core/symbols') | |
| 4 | 4 | const { RequestRetryError } = require('../core/errors') | |
@@ -95,7 +95,7 @@ class RetryHandler { | |||
| 95 | 95 | } | |
| 96 | 96 | ||
| 97 | 97 | onBodySent (chunk) { | |
| 98 | - return this.handler.onBodySent(chunk) | ||
| 98 | + if (this.handler.onBodySent) return this.handler.onBodySent(chunk) | ||
| 99 | 99 | } | |
| 100 | 100 | ||
| 101 | 101 | static [kRetryHandlerDefaultRetry] (err, { state, opts }, cb) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments