How to use the negotiator.Negotiator function in negotiator

To help you get started, we’ve selected a few negotiator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ehmicky / autoserver / src / protocols / adapters / http / content_negotiation / compress.js View on Github external
export const getCompressResponse = function({ specific: { req } }) {
  const negotiator = new Negotiator(req)
  const algos = negotiator.encodings()
  const compressResponse = findAlgo(algos)
  return compressResponse
}
github ehmicky / autoserver / src / protocols / adapters / http / content_negotiation / format.js View on Github external
const getAcceptFormat = function({ specific: { req } }) {
  const negotiator = new Negotiator(req)
  const mimes = negotiator.mediaTypes()

  if (mimes.length === 0) {
    return
  }

  const formatB = mimes
    .map(mime => eGetByMime({ mime, safe: true }))
    .find(formatA => formatA !== undefined)

  if (formatB !== undefined) {
    return formatB.name
  }

  const suggestions = getMimes({ safe: true })
  throwPb({

negotiator

HTTP content negotiation

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis