format: prettify entire project
This commit is contained in:
84
node_modules/undici/lib/handler/cache-revalidation-handler.js
generated
vendored
84
node_modules/undici/lib/handler/cache-revalidation-handler.js
generated
vendored
@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert')
|
||||
const assert = require('node:assert');
|
||||
|
||||
/**
|
||||
* This takes care of revalidation requests we send to the origin. If we get
|
||||
@ -16,109 +16,105 @@ const assert = require('node:assert')
|
||||
* @implements {import('../../types/dispatcher.d.ts').default.DispatchHandler}
|
||||
*/
|
||||
class CacheRevalidationHandler {
|
||||
#successful = false
|
||||
#successful = false;
|
||||
|
||||
/**
|
||||
* @type {((boolean, any) => void) | null}
|
||||
*/
|
||||
#callback
|
||||
#callback;
|
||||
|
||||
/**
|
||||
* @type {(import('../../types/dispatcher.d.ts').default.DispatchHandler)}
|
||||
*/
|
||||
#handler
|
||||
#handler;
|
||||
|
||||
#context
|
||||
#context;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
#allowErrorStatusCodes
|
||||
#allowErrorStatusCodes;
|
||||
|
||||
/**
|
||||
* @param {(boolean) => void} callback Function to call if the cached value is valid
|
||||
* @param {import('../../types/dispatcher.d.ts').default.DispatchHandlers} handler
|
||||
* @param {boolean} allowErrorStatusCodes
|
||||
*/
|
||||
constructor (callback, handler, allowErrorStatusCodes) {
|
||||
constructor(callback, handler, allowErrorStatusCodes) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw new TypeError('callback must be a function')
|
||||
throw new TypeError('callback must be a function');
|
||||
}
|
||||
|
||||
this.#callback = callback
|
||||
this.#handler = handler
|
||||
this.#allowErrorStatusCodes = allowErrorStatusCodes
|
||||
this.#callback = callback;
|
||||
this.#handler = handler;
|
||||
this.#allowErrorStatusCodes = allowErrorStatusCodes;
|
||||
}
|
||||
|
||||
onRequestStart (_, context) {
|
||||
this.#successful = false
|
||||
this.#context = context
|
||||
onRequestStart(_, context) {
|
||||
this.#successful = false;
|
||||
this.#context = context;
|
||||
}
|
||||
|
||||
onRequestUpgrade (controller, statusCode, headers, socket) {
|
||||
this.#handler.onRequestUpgrade?.(controller, statusCode, headers, socket)
|
||||
onRequestUpgrade(controller, statusCode, headers, socket) {
|
||||
this.#handler.onRequestUpgrade?.(controller, statusCode, headers, socket);
|
||||
}
|
||||
|
||||
onResponseStart (
|
||||
controller,
|
||||
statusCode,
|
||||
headers,
|
||||
statusMessage
|
||||
) {
|
||||
assert(this.#callback != null)
|
||||
onResponseStart(controller, statusCode, headers, statusMessage) {
|
||||
assert(this.#callback != null);
|
||||
|
||||
// https://www.rfc-editor.org/rfc/rfc9111.html#name-handling-a-validation-respo
|
||||
// https://datatracker.ietf.org/doc/html/rfc5861#section-4
|
||||
this.#successful = statusCode === 304 ||
|
||||
(this.#allowErrorStatusCodes && statusCode >= 500 && statusCode <= 504)
|
||||
this.#callback(this.#successful, this.#context)
|
||||
this.#callback = null
|
||||
this.#successful =
|
||||
statusCode === 304 ||
|
||||
(this.#allowErrorStatusCodes && statusCode >= 500 && statusCode <= 504);
|
||||
this.#callback(this.#successful, this.#context);
|
||||
this.#callback = null;
|
||||
|
||||
if (this.#successful) {
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
|
||||
this.#handler.onRequestStart?.(controller, this.#context)
|
||||
this.#handler.onRequestStart?.(controller, this.#context);
|
||||
this.#handler.onResponseStart?.(
|
||||
controller,
|
||||
statusCode,
|
||||
headers,
|
||||
statusMessage
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
onResponseData (controller, chunk) {
|
||||
onResponseData(controller, chunk) {
|
||||
if (this.#successful) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
return this.#handler.onResponseData?.(controller, chunk)
|
||||
return this.#handler.onResponseData?.(controller, chunk);
|
||||
}
|
||||
|
||||
onResponseEnd (controller, trailers) {
|
||||
onResponseEnd(controller, trailers) {
|
||||
if (this.#successful) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
this.#handler.onResponseEnd?.(controller, trailers)
|
||||
this.#handler.onResponseEnd?.(controller, trailers);
|
||||
}
|
||||
|
||||
onResponseError (controller, err) {
|
||||
onResponseError(controller, err) {
|
||||
if (this.#successful) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.#callback) {
|
||||
this.#callback(false)
|
||||
this.#callback = null
|
||||
this.#callback(false);
|
||||
this.#callback = null;
|
||||
}
|
||||
|
||||
if (typeof this.#handler.onResponseError === 'function') {
|
||||
this.#handler.onResponseError(controller, err)
|
||||
this.#handler.onResponseError(controller, err);
|
||||
} else {
|
||||
throw err
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CacheRevalidationHandler
|
||||
module.exports = CacheRevalidationHandler;
|
||||
|
Reference in New Issue
Block a user