format: prettify entire project
This commit is contained in:
110
node_modules/undici/lib/handler/unwrap-handler.js
generated
vendored
110
node_modules/undici/lib/handler/unwrap-handler.js
generated
vendored
@ -1,96 +1,106 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
const { parseHeaders } = require('../core/util')
|
||||
const { InvalidArgumentError } = require('../core/errors')
|
||||
const { parseHeaders } = require('../core/util');
|
||||
const { InvalidArgumentError } = require('../core/errors');
|
||||
|
||||
const kResume = Symbol('resume')
|
||||
const kResume = Symbol('resume');
|
||||
|
||||
class UnwrapController {
|
||||
#paused = false
|
||||
#reason = null
|
||||
#aborted = false
|
||||
#abort
|
||||
#paused = false;
|
||||
#reason = null;
|
||||
#aborted = false;
|
||||
#abort;
|
||||
|
||||
[kResume] = null
|
||||
[kResume] = null;
|
||||
|
||||
constructor (abort) {
|
||||
this.#abort = abort
|
||||
constructor(abort) {
|
||||
this.#abort = abort;
|
||||
}
|
||||
|
||||
pause () {
|
||||
this.#paused = true
|
||||
pause() {
|
||||
this.#paused = true;
|
||||
}
|
||||
|
||||
resume () {
|
||||
resume() {
|
||||
if (this.#paused) {
|
||||
this.#paused = false
|
||||
this[kResume]?.()
|
||||
this.#paused = false;
|
||||
this[kResume]?.();
|
||||
}
|
||||
}
|
||||
|
||||
abort (reason) {
|
||||
abort(reason) {
|
||||
if (!this.#aborted) {
|
||||
this.#aborted = true
|
||||
this.#reason = reason
|
||||
this.#abort(reason)
|
||||
this.#aborted = true;
|
||||
this.#reason = reason;
|
||||
this.#abort(reason);
|
||||
}
|
||||
}
|
||||
|
||||
get aborted () {
|
||||
return this.#aborted
|
||||
get aborted() {
|
||||
return this.#aborted;
|
||||
}
|
||||
|
||||
get reason () {
|
||||
return this.#reason
|
||||
get reason() {
|
||||
return this.#reason;
|
||||
}
|
||||
|
||||
get paused () {
|
||||
return this.#paused
|
||||
get paused() {
|
||||
return this.#paused;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = class UnwrapHandler {
|
||||
#handler
|
||||
#controller
|
||||
#handler;
|
||||
#controller;
|
||||
|
||||
constructor (handler) {
|
||||
this.#handler = handler
|
||||
constructor(handler) {
|
||||
this.#handler = handler;
|
||||
}
|
||||
|
||||
static unwrap (handler) {
|
||||
static unwrap(handler) {
|
||||
// TODO (fix): More checks...
|
||||
return !handler.onRequestStart ? handler : new UnwrapHandler(handler)
|
||||
return !handler.onRequestStart ? handler : new UnwrapHandler(handler);
|
||||
}
|
||||
|
||||
onConnect (abort, context) {
|
||||
this.#controller = new UnwrapController(abort)
|
||||
this.#handler.onRequestStart?.(this.#controller, context)
|
||||
onConnect(abort, context) {
|
||||
this.#controller = new UnwrapController(abort);
|
||||
this.#handler.onRequestStart?.(this.#controller, context);
|
||||
}
|
||||
|
||||
onUpgrade (statusCode, rawHeaders, socket) {
|
||||
this.#handler.onRequestUpgrade?.(this.#controller, statusCode, parseHeaders(rawHeaders), socket)
|
||||
onUpgrade(statusCode, rawHeaders, socket) {
|
||||
this.#handler.onRequestUpgrade?.(
|
||||
this.#controller,
|
||||
statusCode,
|
||||
parseHeaders(rawHeaders),
|
||||
socket
|
||||
);
|
||||
}
|
||||
|
||||
onHeaders (statusCode, rawHeaders, resume, statusMessage) {
|
||||
this.#controller[kResume] = resume
|
||||
this.#handler.onResponseStart?.(this.#controller, statusCode, parseHeaders(rawHeaders), statusMessage)
|
||||
return !this.#controller.paused
|
||||
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
||||
this.#controller[kResume] = resume;
|
||||
this.#handler.onResponseStart?.(
|
||||
this.#controller,
|
||||
statusCode,
|
||||
parseHeaders(rawHeaders),
|
||||
statusMessage
|
||||
);
|
||||
return !this.#controller.paused;
|
||||
}
|
||||
|
||||
onData (data) {
|
||||
this.#handler.onResponseData?.(this.#controller, data)
|
||||
return !this.#controller.paused
|
||||
onData(data) {
|
||||
this.#handler.onResponseData?.(this.#controller, data);
|
||||
return !this.#controller.paused;
|
||||
}
|
||||
|
||||
onComplete (rawTrailers) {
|
||||
this.#handler.onResponseEnd?.(this.#controller, parseHeaders(rawTrailers))
|
||||
onComplete(rawTrailers) {
|
||||
this.#handler.onResponseEnd?.(this.#controller, parseHeaders(rawTrailers));
|
||||
}
|
||||
|
||||
onError (err) {
|
||||
onError(err) {
|
||||
if (!this.#handler.onResponseError) {
|
||||
throw new InvalidArgumentError('invalid onError method')
|
||||
throw new InvalidArgumentError('invalid onError method');
|
||||
}
|
||||
|
||||
this.#handler.onResponseError?.(this.#controller, err)
|
||||
this.#handler.onResponseError?.(this.#controller, err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user