Skip to content

Commit

Permalink
replace content-type with fast-content-type-parse (#4505)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Jan 10, 2023
1 parent da047e6 commit 8ebe376
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
17 changes: 2 additions & 15 deletions lib/contentTypeParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

const { AsyncResource } = require('async_hooks')
const lru = require('tiny-lru').lru
// TODO: find more perforamant solution
const { parse: parseContentType } = require('content-type')

const { safeParse: safeParseContentType, defaultContentType } = require('fast-content-type-parse')
const secureJson = require('secure-json-parse')
const {
kDefaultJsonParse,
Expand Down Expand Up @@ -104,7 +102,7 @@ ContentTypeParser.prototype.getParser = function (contentType) {

// dummyContentType always the same object
// we can use === for the comparsion and return early
if (parsed === dummyContentType) {
if (parsed === defaultContentType) {
return this.customParsers.get('')
}

Expand Down Expand Up @@ -360,17 +358,6 @@ function removeAllContentTypeParsers () {
this[kContentTypeParser].removeAll()
}

// dummy here to prevent repeated object creation
const dummyContentType = { type: '', parameters: Object.create(null) }

function safeParseContentType (contentType) {
try {
return parseContentType(contentType)
} catch (err) {
return dummyContentType
}
}

function compareContentType (contentType, parserListItem) {
if (parserListItem.isEssence) {
// we do essence check
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"@fastify/fast-json-stringify-compiler": "^4.1.0",
"abstract-logging": "^2.0.1",
"avvio": "^8.2.0",
"content-type": "^1.0.4",
"fast-content-type-parse": "^1.0.0",
"find-my-way": "^7.3.0",
"light-my-request": "^5.6.1",
"pino": "^8.5.0",
Expand Down

0 comments on commit 8ebe376

Please sign in to comment.