Skip to content

Commit

Permalink
Merge branch 'main' into feat/dns-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 authored Sep 18, 2024
2 parents ce00b6f + 0ad6007 commit 93da79e
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/docs/api/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Returns: `Client`

> ⚠️ Warning: The `H2` support is experimental.
* **bodyTimeout** `number | null` (optional) - Default: `300e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds. Please note the `timeout` will be reset if you keep writing data to the scoket everytime.
* **bodyTimeout** `number | null` (optional) - Default: `300e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds. Please note the `timeout` will be reset if you keep writing data to the socket everytime.
* **headersTimeout** `number | null` (optional) - Default: `300e3` - The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
* **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Defaults to 10 minutes.
* **keepAliveTimeout** `number | null` (optional) - Default: `4e3` - The timeout, in milliseconds, after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details. Defaults to 4 seconds.
Expand Down
2 changes: 1 addition & 1 deletion lib/web/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class Cache {
const reader = stream.getReader()

// 11.3
readAllBytes(reader).then(bodyReadPromise.resolve, bodyReadPromise.reject)
readAllBytes(reader, bodyReadPromise.resolve, bodyReadPromise.reject)
} else {
bodyReadPromise.resolve(undefined)
}
Expand Down
61 changes: 35 additions & 26 deletions lib/web/fetch/constants.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
'use strict'

const corsSafeListedMethods = ['GET', 'HEAD', 'POST']
const corsSafeListedMethods = /** @type {const} */ (['GET', 'HEAD', 'POST'])
const corsSafeListedMethodsSet = new Set(corsSafeListedMethods)

const nullBodyStatus = [101, 204, 205, 304]
const nullBodyStatus = /** @type {const} */ ([101, 204, 205, 304])

const redirectStatus = [301, 302, 303, 307, 308]
const redirectStatus = /** @type {const} */ ([301, 302, 303, 307, 308])
const redirectStatusSet = new Set(redirectStatus)

// https://fetch.spec.whatwg.org/#block-bad-port
const badPorts = [
/**
* @see https://fetch.spec.whatwg.org/#block-bad-port
*/
const badPorts = /** @type {const} */ ([
'1', '7', '9', '11', '13', '15', '17', '19', '20', '21', '22', '23', '25', '37', '42', '43', '53', '69', '77', '79',
'87', '95', '101', '102', '103', '104', '109', '110', '111', '113', '115', '117', '119', '123', '135', '137',
'139', '143', '161', '179', '389', '427', '465', '512', '513', '514', '515', '526', '530', '531', '532',
'540', '548', '554', '556', '563', '587', '601', '636', '989', '990', '993', '995', '1719', '1720', '1723',
'2049', '3659', '4045', '4190', '5060', '5061', '6000', '6566', '6665', '6666', '6667', '6668', '6669', '6679',
'6697', '10080'
]

])
const badPortsSet = new Set(badPorts)

// https://w3c.github.io/webappsec-referrer-policy/#referrer-policies
const referrerPolicy = [
/**
* @see https://w3c.github.io/webappsec-referrer-policy/#referrer-policies
*/
const referrerPolicy = /** @type {const} */ ([
'',
'no-referrer',
'no-referrer-when-downgrade',
Expand All @@ -31,29 +34,31 @@ const referrerPolicy = [
'origin-when-cross-origin',
'strict-origin-when-cross-origin',
'unsafe-url'
]
])
const referrerPolicySet = new Set(referrerPolicy)

const requestRedirect = ['follow', 'manual', 'error']
const requestRedirect = /** @type {const} */ (['follow', 'manual', 'error'])

const safeMethods = ['GET', 'HEAD', 'OPTIONS', 'TRACE']
const safeMethods = /** @type {const} */ (['GET', 'HEAD', 'OPTIONS', 'TRACE'])
const safeMethodsSet = new Set(safeMethods)

const requestMode = ['navigate', 'same-origin', 'no-cors', 'cors']
const requestMode = /** @type {const} */ (['navigate', 'same-origin', 'no-cors', 'cors'])

const requestCredentials = ['omit', 'same-origin', 'include']
const requestCredentials = /** @type {const} */ (['omit', 'same-origin', 'include'])

const requestCache = [
const requestCache = /** @type {const} */ ([
'default',
'no-store',
'reload',
'no-cache',
'force-cache',
'only-if-cached'
]
])

// https://fetch.spec.whatwg.org/#request-body-header-name
const requestBodyHeader = [
/**
* @see https://fetch.spec.whatwg.org/#request-body-header-name
*/
const requestBodyHeader = /** @type {const} */ ([
'content-encoding',
'content-language',
'content-location',
Expand All @@ -63,18 +68,22 @@ const requestBodyHeader = [
// removed in the Headers implementation. However, undici doesn't
// filter out headers, so we add it here.
'content-length'
]
])

// https://fetch.spec.whatwg.org/#enumdef-requestduplex
const requestDuplex = [
/**
* @see https://fetch.spec.whatwg.org/#enumdef-requestduplex
*/
const requestDuplex = /** @type {const} */ ([
'half'
]
])

// http://fetch.spec.whatwg.org/#forbidden-method
const forbiddenMethods = ['CONNECT', 'TRACE', 'TRACK']
/**
* @see http://fetch.spec.whatwg.org/#forbidden-method
*/
const forbiddenMethods = /** @type {const} */ (['CONNECT', 'TRACE', 'TRACK'])
const forbiddenMethodsSet = new Set(forbiddenMethods)

const subresource = [
const subresource = /** @type {const} */ ([
'audio',
'audioworklet',
'font',
Expand All @@ -87,7 +96,7 @@ const subresource = [
'video',
'xslt',
''
]
])
const subresourceSet = new Set(subresource)

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions lib/web/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1889,8 +1889,8 @@ async function httpNetworkFetch (

// 11. Let pullAlgorithm be an action that resumes the ongoing fetch
// if it is suspended.
const pullAlgorithm = async () => {
await fetchParams.controller.resume()
const pullAlgorithm = () => {
return fetchParams.controller.resume()
}

// 12. Let cancelAlgorithm be an algorithm that aborts fetchParams’s
Expand Down
47 changes: 26 additions & 21 deletions lib/web/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ function iteratorMixin (name, object, kInternalIterator, keyIndex = 0, valueInde
/**
* @see https://fetch.spec.whatwg.org/#body-fully-read
*/
async function fullyReadBody (body, processBody, processBodyError) {
function fullyReadBody (body, processBody, processBodyError) {
// 1. If taskDestination is null, then set taskDestination to
// the result of starting a new parallel queue.

Expand All @@ -1054,11 +1054,7 @@ async function fullyReadBody (body, processBody, processBodyError) {
}

// 5. Read all bytes from reader, given successSteps and errorSteps.
try {
successSteps(await readAllBytes(reader))
} catch (e) {
errorSteps(e)
}
readAllBytes(reader, successSteps, errorSteps)
}

/**
Expand Down Expand Up @@ -1096,30 +1092,39 @@ function isomorphicEncode (input) {
* @see https://streams.spec.whatwg.org/#readablestreamdefaultreader-read-all-bytes
* @see https://streams.spec.whatwg.org/#read-loop
* @param {ReadableStreamDefaultReader} reader
* @param {(bytes: Uint8Array) => void} successSteps
* @param {(error: Error) => void} failureSteps
*/
async function readAllBytes (reader) {
async function readAllBytes (reader, successSteps, failureSteps) {
const bytes = []
let byteLength = 0

while (true) {
const { done, value: chunk } = await reader.read()
try {
do {
const { done, value: chunk } = await reader.read()

if (done) {
// 1. Call successSteps with bytes.
return Buffer.concat(bytes, byteLength)
}
if (done) {
// 1. Call successSteps with bytes.
successSteps(Buffer.concat(bytes, byteLength))
return
}

// 1. If chunk is not a Uint8Array object, call failureSteps
// with a TypeError and abort these steps.
if (!isUint8Array(chunk)) {
throw new TypeError('Received non-Uint8Array chunk')
}
// 1. If chunk is not a Uint8Array object, call failureSteps
// with a TypeError and abort these steps.
if (!isUint8Array(chunk)) {
failureSteps(TypeError('Received non-Uint8Array chunk'))
return
}

// 2. Append the bytes represented by chunk to bytes.
bytes.push(chunk)
byteLength += chunk.length
// 2. Append the bytes represented by chunk to bytes.
bytes.push(chunk)
byteLength += chunk.length

// 3. Read-loop given reader, bytes, successSteps, and failureSteps.
} while (true)
} catch (e) {
// 1. Call failureSteps with e.
failureSteps(e)
}
}

Expand Down
88 changes: 88 additions & 0 deletions test/fixtures/wpt/resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,82 @@
*/
run_bounce_tracking_mitigations: function (context = null) {
return window.test_driver_internal.run_bounce_tracking_mitigations(context);
},

/**
* Creates a virtual pressure source.
*
* Matches the `Create virtual pressure source
* <https://w3c.github.io/compute-pressure/#create-virtual-pressure-source>`_
* WebDriver command.
*
* @param {String} source_type - A `virtual pressure source type
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
* such as "cpu".
* @param {Object} [metadata={}] - Optional parameters described
* in `Create virtual pressure source
* <https://w3c.github.io/compute-pressure/#create-virtual-pressure-source>`_.
* @param {WindowProxy} [context=null] - Browsing context in which to
* run the call, or null for the
* current browsing context.
*
* @returns {Promise} Fulfilled when virtual pressure source is created.
* Rejected in case the WebDriver command errors out
* (including if a virtual pressure source of the
* same type already exists).
*/
create_virtual_pressure_source: function(source_type, metadata={}, context=null) {
return window.test_driver_internal.create_virtual_pressure_source(source_type, metadata, context);
},

/**
* Causes a virtual pressure source to report a new reading.
*
* Matches the `Update virtual pressure source
* <https://w3c.github.io/compute-pressure/#update-virtual-pressure-source>`_
* WebDriver command.
*
* @param {String} source_type - A `virtual pressure source type
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
* such as "cpu".
* @param {String} sample - A `virtual pressure state
* <https://w3c.github.io/compute-pressure/#dom-pressurestate>`_
* such as "critical".
* @param {WindowProxy} [context=null] - Browsing context in which to
* run the call, or null for the
* current browsing context.
*
* @returns {Promise} Fulfilled after the reading update reaches the
* virtual pressure source. Rejected in case the
* WebDriver command errors out (including if a
* virtual pressure source of the given type does not
* exist).
*/
update_virtual_pressure_source: function(source_type, sample, context=null) {
return window.test_driver_internal.update_virtual_pressure_source(source_type, sample, context);
},

/**
* Removes created virtual pressure source.
*
* Matches the `Delete virtual pressure source
* <https://w3c.github.io/compute-pressure/#delete-virtual-pressure-source>`_
* WebDriver command.
*
* @param {String} source_type - A `virtual pressure source type
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
* such as "cpu".
* @param {WindowProxy} [context=null] - Browsing context in which to
* run the call, or null for the
* current browsing context.
*
* @returns {Promise} Fulfilled after the virtual pressure source has
* been removed or if a pressure source of the given
* type does not exist. Rejected in case the
* WebDriver command errors out.
*/
remove_virtual_pressure_source: function(source_type, context=null) {
return window.test_driver_internal.remove_virtual_pressure_source(source_type, context);
}
};

Expand Down Expand Up @@ -1356,6 +1432,18 @@

async run_bounce_tracking_mitigations(context=null) {
throw new Error("run_bounce_tracking_mitigations() is not implemented by testdriver-vendor.js");
},

async create_virtual_pressure_source(source_type, metadata={}, context=null) {
throw new Error("create_virtual_pressure_source() is not implemented by testdriver-vendor.js");
},

async update_virtual_pressure_source(source_type, sample, context=null) {
throw new Error("update_virtual_pressure_source() is not implemented by testdriver-vendor.js");
},

async remove_virtual_pressure_source(source_type, context=null) {
throw new Error("remove_virtual_pressure_source() is not implemented by testdriver-vendor.js");
}
};
})();

0 comments on commit 93da79e

Please sign in to comment.