Conversation
|
Node: 20 Node: 22 |
|
Node: 20 Node: 22 |
|
We currently don't have this:
|
|
cant we avoid somehow toLowerCase? |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
We already call |
|
I would say we should do something like this. The intention is that we cache both any-case header and lowercase header. Please be aware ContentTypeParser.prototype.getParser = function (contentType) {
// fast-path for remembered content-type (incoming as lowercase)
let parser = this.customParsers.get(contentType)
if (parser !== undefined) return parser
parser = this.cache.get(contentType)
if (parser !== undefined) return parser
// case-incensitive cache check
const lowercaseContentType = contentType.toLowerCase()
let parser = this.customParsers.get(lowercaseContentType)
if (parser !== undefined) return parser
parser = this.cache.get(lowercaseContentType)
if (parser !== undefined) return parser
// eslint-disable-next-line no-var
for (var i = 0; i !== this.parserList.length; ++i) {
const parserListItem = this.parserList[i]
if (
lowercaseContentType.slice(0, parserListItem.length) === parserListItem &&
(lowercaseContentType.length === parserListItem.length || lowercaseContentType.charCodeAt(parserListItem.length) === 59 /* `;` */ || lowercaseContentType.charCodeAt(parserListItem.length) === 32 /* ` ` */)
) {
parser = this.customParsers.get(parserListItem)
this.cache.set(contentType, parser)
// cache for both lowercase and original header
this.cache.set(lowercaseContentType, parser)
return parser
}
}
// eslint-disable-next-line no-var
for (var j = 0; j !== this.parserRegExpList.length; ++j) {
const parserRegExp = this.parserRegExpList[j]
// regexp should use the original header in all case
// it allows the user to choose whether they want case-sensitive or case-insensitive
if (parserRegExp.test(contentType)) {
parser = this.customParsers.get(parserRegExp.toString())
this.cache.set(contentType, parser)
// cache for both lowercase and original header
this.cache.set(lowercaseContentType, parser)
return parser
}
}
return this.customParsers.get('')
} |
metcoder95
left a comment
There was a problem hiding this comment.
This should be fine, the benchmarks doesn't show a big difference and should be fine.
Nevertheless, the suggestion of caching from @climba03003 seems quite interesting; adding a disclosure of the multipart/form-data limitations might be sufficient.
|
@climba03003 wdyt? I like this approach! Every string Content-Type parser is lowercase , so: If we miss the original cache checks, then we lowercase and try to match manually like before If we match there, then we save the original version to the cache for future matches |
|
Note that this only applies to string content-type parsers Like you said, RegExp offers more freedom in how a user would want to match |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
so this actually correctly fixes #5740
standards say
Content-Typeis case insensitive, which is why we prevent the registration oftext/htmlandtext/HTMLat the same time, but currently don't treat text/html and text/HTML as the same