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

Function onSessionHeaders

lib/internal/http2/core.js:359–475  ·  view source on GitHub ↗
(handle, id, cat, flags, headers, sensitiveHeaders)

Source from the content-addressed store, hash-verified

357// event. If the stream is not new, emit the 'headers' event to pass
358// the block of headers on.
359function onSessionHeaders(handle, id, cat, flags, headers, sensitiveHeaders) {
360 const session = this[kOwner];
361 if (session.destroyed)
362 return;
363
364 const type = session[kType];
365 session[kUpdateTimer]();
366 debugStream(id, type, 'headers received');
367 const streams = session[kState].streams;
368
369 const endOfStream = !!(flags & NGHTTP2_FLAG_END_STREAM);
370 let stream = streams.get(id);
371
372 // Convert the array of header name value pairs into an object
373 const obj = toHeaderObject(headers, sensitiveHeaders);
374
375 if (stream === undefined) {
376 if (session.closed) {
377 // We are not accepting any new streams at this point. This callback
378 // should not be invoked at this point in time, but just in case it is,
379 // refuse the stream using an RST_STREAM and destroy the handle.
380 handle.rstStream(NGHTTP2_REFUSED_STREAM);
381 handle.destroy();
382 return;
383 }
384 // session[kType] can be only one of two possible values
385 if (type === NGHTTP2_SESSION_SERVER) {
386 // eslint-disable-next-line no-use-before-define
387 stream = new ServerHttp2Stream(session, handle, id, {}, obj);
388 if (onServerStreamCreatedChannel.hasSubscribers) {
389 onServerStreamCreatedChannel.publish({
390 stream,
391 headers: obj,
392 });
393 }
394 if (onServerStreamStartChannel.hasSubscribers) {
395 onServerStreamStartChannel.publish({
396 stream,
397 headers: obj,
398 });
399 }
400 if (endOfStream) {
401 stream.push(null);
402 }
403 if (obj[HTTP2_HEADER_METHOD] === HTTP2_METHOD_HEAD) {
404 // For head requests, there must not be a body...
405 // end the writable side immediately.
406 stream.end();
407 stream[kState].flags |= STREAM_FLAGS_HEAD_REQUEST;
408 }
409 } else {
410 // eslint-disable-next-line no-use-before-define
411 stream = new ClientHttp2Stream(session, handle, id, {});
412 if (onClientStreamCreatedChannel.hasSubscribers) {
413 onClientStreamCreatedChannel.publish({
414 stream,
415 headers: obj,
416 });

Callers

nothing calls this directly

Calls 10

debugStreamFunction · 0.85
toHeaderObjectFunction · 0.85
initOriginSetFunction · 0.85
runInAsyncScopeMethod · 0.80
getMethod · 0.65
deleteMethod · 0.65
destroyMethod · 0.45
publishMethod · 0.45
pushMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…