(req, res, params, context, query)
| 455 | |
| 456 | // HTTP request entry point, the routing has already been executed |
| 457 | function routeHandler (req, res, params, context, query) { |
| 458 | const id = getGenReqId(context.server, req) |
| 459 | |
| 460 | let childLogger |
| 461 | if (hasLogger === false && context.childLoggerFactory === defaultChildLoggerFactory) { |
| 462 | // the null logger children are the logger itself, so we can skip |
| 463 | // the child logger creation altogether |
| 464 | childLogger = logger |
| 465 | } else { |
| 466 | const loggerOpts = { |
| 467 | level: context.logLevel |
| 468 | } |
| 469 | |
| 470 | if (context.logSerializers) { |
| 471 | loggerOpts.serializers = context.logSerializers |
| 472 | } |
| 473 | childLogger = createChildLogger(context, logger, req, id, loggerOpts) |
| 474 | } |
| 475 | |
| 476 | if (closing === true) { |
| 477 | /* istanbul ignore next mac, windows */ |
| 478 | if (req.httpVersionMajor !== 2) { |
| 479 | res.setHeader('Connection', 'close') |
| 480 | } |
| 481 | |
| 482 | // Load-shedding fast path during drain. server.close() and |
| 483 | // closeIdleConnections() only reap idle sockets; requests already |
| 484 | // pipelined or arriving on an active keep-alive connection still reach |
| 485 | // this point with closing === true. Short-circuiting with 503 avoids |
| 486 | // running the full handler chain (and any downstream calls) for work |
| 487 | // the load balancer should redirect elsewhere. |
| 488 | if (return503OnClosing) { |
| 489 | const headers = { |
| 490 | 'Content-Type': 'application/json', |
| 491 | 'Content-Length': '80' |
| 492 | } |
| 493 | res.writeHead(503, headers) |
| 494 | res.end('{"error":"Service Unavailable","message":"Service Unavailable","statusCode":503}') |
| 495 | |
| 496 | context.server[kLogController].serviceUnavailable(childLogger, context.server) |
| 497 | |
| 498 | return |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | // When server.forceCloseConnections is true, we will collect any requests |
| 503 | // that have indicated they want persistence so that they can be reaped |
| 504 | // on server close. Otherwise, the container is a noop container. |
| 505 | const connHeader = String.prototype.toLowerCase.call(req.headers.connection || '') |
| 506 | if (connHeader === 'keep-alive') { |
| 507 | if (keepAliveConnections.has(req.socket) === false) { |
| 508 | keepAliveConnections.add(req.socket) |
| 509 | req.socket.on('close', removeTrackedSocket.bind({ keepAliveConnections, socket: req.socket })) |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | // we revert the changes in defaultRoute |
| 514 | if (req.headers[kRequestAcceptVersion] !== undefined) { |
nothing calls this directly
no test coverage detected