@grafctory/http - v0.9.0
    Preparing search index...

    Function getMedia

    • Retrieves the media type of the target of a request.

      Note

      The media type is identified the way a static server identifies it, by the extension of the file the target names. Extensions are matched case-insensitively, and the query and the fragment are ignored. A path ending in a slash names no file, and a hidden file such as .profile has no extension.

      The default media types cover the textual formats a site commonly serves, YAML included under the type RFC 9512 registers. Media types stated by types take precedence, so a caller may add an extension or remap a known one.

      A target with no known extension is assigned the wildcard media range, which matches any media type. The returned type is therefore always a valid media range, ready to be stated as is in the Accept header of a request.

      Parameters

      • input: RequestInfo | URL

        The request or target URL the media type is to be retrieved from

      • types: { readonly [extension: string]: string } = {}

        The extra media types, keyed by lowercase extension, taking precedence over the default ones

      Returns string

      The media type of the extension of the file the target names, or the wildcard media range if the target names no file, or a file whose extension is missing or listed neither by types nor by the defaults

      TypeError If input states a target that is not an absolute URI