@ fastify/接受-谈判者
接受*标题的谈判者.
安装
npm i @fastify/accept-negotiator
使用量
模块导出一个函数, 您可以用于谈判一个接受- * 标题, 如 accept-encoding。它需要两个参数:
negotiate(header, supportedValues)
header(单位:千美元)string——接受方,例如接受-编码supportedValues(单位:千美元)string[]—— 所支持的数值
const negotiate = require('@fastify/accept-negotiator').negotiate
const encoding = negotiate('gzip, deflate, br', ['br'])
console.log(encoding) // 'br*
该模块还输出一个可用于谈判接受-*标题的类,并使用缓存来提高性能.
Negotiate(supportedValues)
supportedValues(单位:千美元)string[]—— 所支持的数值cache(单位:千美元){ set: Function; get: Function; has: Function },可选) - 缓存- Store,例如ES6-Map或mnemonist LRUCache
const Negotiator = require('@fastify/accept-negotiator').Negotiator
const encodingNegotiator = new Negotiator({ supportedValues: ['br'], cache: new Map() })
const encoding = encodingNegotiator.negotiate('gzip, deflate, br')
console.log(encoding) // 'br*
许可证
许可证根据 麻省理工学院。 。 。 .