Skip to content

Commit

Permalink
code review pt2
Browse files Browse the repository at this point in the history
Signed-off-by: flakey5 <[email protected]>
  • Loading branch information
flakey5 committed Oct 14, 2024
1 parent baaa914 commit 0194f19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/core/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ Object.setPrototypeOf(headerNameLowerCasedRecord, null)
*/
const wellknownHeaderNameBuffers = {}

// Note: object prototypes should not be able to be referenced. e.g. `Object#hasOwnProperty`.
Object.setPrototypeOf(wellknownHeaderNameBuffers, null)

/**
* @param {string} header Lowercased header
* @returns {Buffer}
*/
function getWellknownHeaderNameBuffer (header) {
function getHeaderNameAsBuffer (header) {
let buffer = wellknownHeaderNameBuffers[header]

if (buffer === undefined) {
Expand All @@ -136,6 +139,5 @@ for (let i = 0; i < wellknownHeaderNames.length; ++i) {
module.exports = {
wellknownHeaderNames,
headerNameLowerCasedRecord,
wellknownHeaderNameBuffers,
getWellknownHeaderNameBuffer
getHeaderNameAsBuffer
}
4 changes: 2 additions & 2 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const nodeUtil = require('node:util')
const { stringify } = require('node:querystring')
const { EventEmitter: EE } = require('node:events')
const { InvalidArgumentError } = require('./errors')
const { headerNameLowerCasedRecord, getWellknownHeaderNameBuffer } = require('./constants')
const { headerNameLowerCasedRecord, getHeaderNameAsBuffer } = require('./constants')
const { tree } = require('./tree')

const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(v => Number(v))
Expand Down Expand Up @@ -462,7 +462,7 @@ function encodeHeaders (headers) {
rawValue = Buffer.from(value)
}

const headerBuffer = getWellknownHeaderNameBuffer(header)
const headerBuffer = getHeaderNameAsBuffer(header)

rawHeaders[rawHeadersIndex] = headerBuffer
rawHeadersIndex++
Expand Down

0 comments on commit 0194f19

Please sign in to comment.