-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: disable/ignore request-id header (#4193)
* add option to disable/ignore request-id header fixes #4192 * add more restrictive schema definition * update configValidator generated by running 'node build/build-validation.js' after change on 'build-validation.js' * move logic into reqIdGenFactory * update docs for requestHeaderId Adding documentation for opt-out of 'requestHeaderId'
- Loading branch information
1 parent
ea8aae9
commit 4e79725
Showing
11 changed files
with
207 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 1,26 @@ | ||
'use strict' | ||
|
||
module.exports = function () { | ||
module.exports = function (requestIdHeader, optGenReqId) { | ||
// 2,147,483,647 (2^31 − 1) stands for max SMI value (an internal optimization of V8). | ||
// With this upper bound, if you'll be generating 1k ids/sec, you're going to hit it in ~25 days. | ||
// This is very likely to happen in real-world applications, hence the limit is enforced. | ||
// Growing beyond this value will make the id generation slower and cause a deopt. | ||
// In the worst cases, it will become a float, losing accuracy. | ||
const maxInt = 2147483647 | ||
let nextReqId = 0 | ||
return function genReqId (req) { | ||
function defaultGenReqId (req) { | ||
nextReqId = (nextReqId 1) & maxInt | ||
return `req-${nextReqId.toString(36)}` | ||
} | ||
|
||
const genReqId = optGenReqId || defaultGenReqId | ||
|
||
if (requestIdHeader) { | ||
// requestIdHeader = typeof requestIdHeader === 'string' ? requestIdHeader : 'request-id' | ||
return function (req) { | ||
return req.headers[requestIdHeader] || genReqId(req) | ||
} | ||
} | ||
|
||
return genReqId | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.