Skip to content

Commit

Permalink
replace content-type with fast-content-type-parse (#4505) (#4507)
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/contentTypeParser.js
#	package.json

Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>
  • Loading branch information
climba03003 and Uzlopak committed Jan 10, 2023
1 parent e4e8393 commit fcc931e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 2 additions & 13 deletions lib/contentTypeParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let lru = require('tiny-lru')
// See https://github.com/fastify/fastify/issues/2356
// and https://github.com/fastify/fastify/discussions/2907.
lru = typeof lru === 'function' ? lru : lru.default
const { parse: parseContentType } = require('content-type')
const { safeParse: safeParseContentType, defaultContentType } = require('fast-content-type-parse')

const secureJson = require('secure-json-parse')
const {
Expand Down Expand Up @@ -108,7 +108,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 @@ -366,17 +366,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 @@ -181,13 +181,13 @@
"@fastify/error": "^2.0.0",
"abstract-logging": "^2.0.0",
"avvio": "^7.1.2",
"fast-content-type-parse": "^1.0.0",
"fast-json-stringify": "^2.5.2",
"find-my-way": "^4.5.0",
"flatstr": "^1.0.12",
"light-my-request": "^4.2.0",
"pino": "^6.13.0",
"process-warning": "^1.0.0",
"content-type": "^1.0.4",
"proxy-addr": "^2.0.7",
"rfdc": "^1.1.4",
"secure-json-parse": "^2.0.0",
Expand Down

0 comments on commit fcc931e

Please sign in to comment.