MCPcopy
hub / github.com/nodejs/undici / assertRequestHandler

Function assertRequestHandler

lib/core/util.js:562–600  ·  view source on GitHub ↗

* Asserts that the handler object is a request handler. * * @param {object} handler * @param {string} method * @param {string} [upgrade] * @returns {asserts handler is import('../api/api-request').RequestHandler}

(handler, method, upgrade)

Source from the content-addressed store, hash-verified

560 * @returns {asserts handler is import('../api/api-request').RequestHandler}
561 */
562function assertRequestHandler (handler, method, upgrade) {
563 if (!handler || typeof handler !== 'object') {
564 throw new InvalidArgumentError('handler must be an object')
565 }
566
567 if (typeof handler.onRequestStart !== 'function') {
568 throw new InvalidArgumentError('invalid onRequestStart method')
569 }
570
571 if (typeof handler.onResponseError !== 'function') {
572 throw new InvalidArgumentError('invalid onResponseError method')
573 }
574
575 if (typeof handler.onBodySent !== 'function' && handler.onBodySent !== undefined) {
576 throw new InvalidArgumentError('invalid onBodySent method')
577 }
578
579 if (typeof handler.onRequestSent !== 'function' && handler.onRequestSent !== undefined) {
580 throw new InvalidArgumentError('invalid onRequestSent method')
581 }
582
583 if (upgrade || method === 'CONNECT') {
584 if (typeof handler.onRequestUpgrade !== 'function') {
585 throw new InvalidArgumentError('invalid onRequestUpgrade method')
586 }
587 } else {
588 if (typeof handler.onResponseStart !== 'function') {
589 throw new InvalidArgumentError('invalid onResponseStart method')
590 }
591
592 if (typeof handler.onResponseData !== 'function') {
593 throw new InvalidArgumentError('invalid onResponseData method')
594 }
595
596 if (typeof handler.onResponseEnd !== 'function') {
597 throw new InvalidArgumentError('invalid onResponseEnd method')
598 }
599 }
600}
601
602/**
603 * A body is disturbed if it has been read from and it cannot be re-used without

Callers 1

constructorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…