Home / Function/ getParser() — fastify Function Reference

getParser() — fastify Function Reference

Architecture documentation for the getParser() function in content-type-parser.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  85b7c491_fec4_f37f_2d94_fa3bd924a97b["getParser()"]
  b47c11f3_fe3b_64dc_0f58_921e5921ec45["content-type-parser.js"]
  85b7c491_fec4_f37f_2d94_fa3bd924a97b -->|defined in| b47c11f3_fe3b_64dc_0f58_921e5921ec45
  2cc48675_3506_ea24_6a37_4a303bc97431["run()"]
  2cc48675_3506_ea24_6a37_4a303bc97431 -->|calls| 85b7c491_fec4_f37f_2d94_fa3bd924a97b
  style 85b7c491_fec4_f37f_2d94_fa3bd924a97b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/content-type-parser.js lines 119–154

ContentTypeParser.prototype.getParser = function (contentType) {
  if (typeof contentType === 'string') {
    contentType = new ContentType(contentType)
  }
  const ct = contentType.toString()

  let parser = this.cache.get(ct)
  if (parser !== undefined) return parser
  parser = this.customParsers.get(ct)
  if (parser !== undefined) {
    this.cache.set(ct, parser)
    return parser
  }

  // We have conflicting desires across our test suite. In some cases, we
  // expect to get a parser by just passing the media-type. In others, we expect
  // to get a parser registered under the media-type while also providing
  // parameters. And in yet others, we expect to register a parser under the
  // media-type and have it apply to any request with a header that starts
  // with that type.
  parser = this.customParsers.get(contentType.mediaType)
  if (parser !== undefined) {
    return parser
  }

  for (let j = 0; j !== this.parserRegExpList.length; ++j) {
    const parserRegExp = this.parserRegExpList[j]
    if (parserRegExp.test(ct)) {
      parser = this.customParsers.get(parserRegExp.toString())
      this.cache.set(ct, parser)
      return parser
    }
  }

  return this.customParsers.get('')
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does getParser() do?
getParser() is a function in the fastify codebase, defined in lib/content-type-parser.js.
Where is getParser() defined?
getParser() is defined in lib/content-type-parser.js at line 119.
What calls getParser()?
getParser() is called by 1 function(s): run.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free