Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "util/HeaderUtil"

Index

Variables

Const logger

logger: Logger = getLoggerFor('HeaderUtil')

Const token

token: RegExp = /^[a-zA-Z0-9!#$%&'*+-.^_`|~]+$/u

Functions

Const addHeader

  • addHeader(response: HttpResponse, name: string, value: string | string[]): void

Const parseAccept

  • parseAccept(input: string): Accept[]

Const parseAcceptCharset

Const parseAcceptEncoding

Const parseAcceptLanguage

Const parseAcceptPart

  • parseAcceptPart(part: string, replacements: Record<string, string>): Accept
  • Parses a single media range with corresponding parameters from an Accept header. For every parameter value that is a double quoted string, we check if it is a key in the replacements map. If yes the value from the map gets inserted instead.

    throws

    BadRequestHttpError Thrown on invalid type, qvalue or parameter syntax.

    Parameters

    • part: string

      A string corresponding to a media range and its corresponding parameters.

    • replacements: Record<string, string>

      The double quoted strings that need to be replaced.

    Returns Accept

    Accept object corresponding to the header string.

Const parseForwarded

  • Parses a Forwarded header value.

    Parameters

    • Default value value: string = ""

      The Forwarded header value.

    Returns Forwarded

    The parsed Forwarded header.

Const parseNoParameters

  • parseNoParameters(input: string): { range: string; weight: number }[]
  • Parses an Accept-* header where each part is only a value and a weight, so roughly /.(q=.)?/ separated by commas.

    throws

    BadRequestHttpError Thrown on invalid qvalue syntax.

    Parameters

    • input: string

      Input header string.

    Returns { range: string; weight: number }[]

    An array of ranges and weights.

Const parseParameters

  • parseParameters(parameters: string[], replacements: Record<string, string>): { name: string; value: string }[]
  • Parses a list of split parameters and checks their validity.

    throws

    BadRequestHttpError Thrown on invalid parameter syntax.

    Parameters

    • parameters: string[]

      A list of split parameters (token [ "=" ( token / quoted-string ) ])

    • replacements: Record<string, string>

      The double quoted strings that need to be replaced.

    Returns { name: string; value: string }[]

    An array of name/value objects corresponding to the parameters.

Const splitAndClean

  • splitAndClean(input: string): string[]
  • Splits the input string on commas, trims all parts and filters out empty ones.

    Parameters

    • input: string

      Input header string.

    Returns string[]

Const testQValue

  • testQValue(qvalue: string): void

Const transformQuotedStrings

  • transformQuotedStrings(input: string): { replacements: Record<string, string>; result: string }
  • Replaces all double quoted strings in the input string with "0", "1", etc.

    Parameters

    • input: string

      The Accept header string.

    Returns { replacements: Record<string, string>; result: string }

    The transformed string and a map with keys "0", etc. and values the original string that was there.

    • replacements: Record<string, string>
    • result: string