MCPcopy Create free account
hub / github.com/angular/dev-infra / onHeadersComplete

Method onHeadersComplete

github-actions/browserstack/set-browserstack-env.js:6277–6358  ·  view source on GitHub ↗
(statusCode, upgrade, shouldKeepAlive)

Source from the content-addressed store, hash-verified

6275 client[kHTTPContext] = null;
6276 client[kQueue][client[kRunningIdx]++] = null;
6277 client.emit("disconnect", client[kUrl], [client], new InformationalError("upgrade"));
6278 try {
6279 request.onUpgrade(statusCode, headers, socket);
6280 } catch (err) {
6281 util.destroy(socket, err);
6282 }
6283 client[kResume]();
6284 }
6285 onHeadersComplete(statusCode, upgrade, shouldKeepAlive) {
6286 const { client, socket, headers, statusText } = this;
6287 if (socket.destroyed) {
6288 return -1;
6289 }
6290 if (client[kRunning] === 0) {
6291 util.destroy(socket, new SocketError("bad response", util.getSocketInfo(socket)));
6292 return -1;
6293 }
6294 const request = client[kQueue][client[kRunningIdx]];
6295 if (!request) {
6296 return -1;
6297 }
6298 assert(!this.upgrade);
6299 assert(this.statusCode < 200);
6300 if (statusCode === 100) {
6301 util.destroy(socket, new SocketError("bad response", util.getSocketInfo(socket)));
6302 return -1;
6303 }
6304 if (upgrade && !request.upgrade) {
6305 util.destroy(socket, new SocketError("bad upgrade", util.getSocketInfo(socket)));
6306 return -1;
6307 }
6308 assert(this.timeoutType === TIMEOUT_HEADERS);
6309 this.statusCode = statusCode;
6310 this.shouldKeepAlive = shouldKeepAlive || // Override llhttp value which does not allow keepAlive for HEAD.
6311 request.method === "HEAD" && !socket[kReset] && this.connection.toLowerCase() === "keep-alive";
6312 if (this.statusCode >= 200) {
6313 const bodyTimeout = request.bodyTimeout != null ? request.bodyTimeout : client[kBodyTimeout];
6314 this.setTimeout(bodyTimeout, TIMEOUT_BODY);
6315 } else if (this.timeout) {
6316 if (this.timeout.refresh) {
6317 this.timeout.refresh();
6318 }
6319 }
6320 if (request.method === "CONNECT") {
6321 assert(client[kRunning] === 1);
6322 this.upgrade = true;
6323 return 2;
6324 }
6325 if (upgrade) {
6326 assert(client[kRunning] === 1);
6327 this.upgrade = true;
6328 return 2;
6329 }
6330 assert((this.headers.length & 1) === 0);
6331 this.headers = [];
6332 this.headersSize = 0;
6333 if (this.shouldKeepAlive && client[kPipelining]) {
6334 const keepAliveTimeout = this.keepAlive ? util.parseKeepAliveTimeout(this.keepAlive) : null;

Callers 1

lazyllhttpFunction · 0.45

Calls 4

destroyMethod · 0.45
setTimeoutMethod · 0.45
refreshMethod · 0.45
onHeadersMethod · 0.45

Tested by

no test coverage detected