MCPcopy Index your code
hub / github.com/nodejs/node / onUpgrade

Method onUpgrade

deps/undici/undici.js:7417–7448  ·  view source on GitHub ↗

* @param {Buffer} head

(head)

Source from the content-addressed store, hash-verified

7415 * @param {Buffer} head
7416 */
7417 onUpgrade(head) {
7418 const { upgrade, client, socket, headers, statusCode } = this;
7419 assert(upgrade);
7420 assert(client[kSocket] === socket);
7421 assert(!socket.destroyed);
7422 assert(!this.paused);
7423 assert((headers.length & 1) === 0);
7424 const request = client[kQueue][client[kRunningIdx]];
7425 assert(request);
7426 assert(request.upgrade || request.method === "CONNECT");
7427 this.statusCode = 0;
7428 this.statusText = "";
7429 this.shouldKeepAlive = false;
7430 this.headers = [];
7431 this.headersSize = 0;
7432 socket.unshift(head);
7433 socket[kParser].destroy();
7434 socket[kParser] = null;
7435 socket[kClient] = null;
7436 socket[kError] = null;
7437 removeAllListeners(socket);
7438 client[kSocket] = null;
7439 client[kHTTPContext] = null;
7440 client[kQueue][client[kRunningIdx]++] = null;
7441 client.emit("disconnect", client[kUrl], [client], new InformationalError("upgrade"));
7442 try {
7443 request.onRequestUpgrade(statusCode, headers, socket);
7444 } catch (err) {
7445 util.destroy(socket, err);
7446 }
7447 client[kResume]();
7448 }
7449 /**
7450 * @param {number} statusCode
7451 * @param {boolean} upgrade

Callers 2

executeMethod · 0.45
onRequestUpgradeMethod · 0.45

Calls 6

unshiftMethod · 0.80
removeAllListenersFunction · 0.70
onRequestUpgradeMethod · 0.65
assertFunction · 0.50
destroyMethod · 0.45
emitMethod · 0.45

Tested by

no test coverage detected