61 lines
1.6 KiB
Racket
61 lines
1.6 KiB
Racket
#lang scribble/manual
|
|
|
|
@(require racket/base
|
|
scribble/core
|
|
(for-label racket/base
|
|
racket/string
|
|
racket/file))
|
|
|
|
@title{mimetypes}
|
|
@author[@author+email["Hans Dijkema" "hans@dijkewijk.nl"]]
|
|
|
|
@defmodule[mimetypes]
|
|
|
|
MIME type utilities used by the webview library.
|
|
|
|
This module provides a mapping from file extensions to MIME types together with
|
|
a function to determine the MIME type of a file path.
|
|
|
|
@section{Overview}
|
|
|
|
The module is used by the local HTTPS server to determine the correct
|
|
@tt{Content-Type} header when serving files.
|
|
|
|
MIME types are determined based on the file extension.
|
|
|
|
@section{Function: path->mimetype}
|
|
|
|
@defproc[(path->mimetype [p path-string?]) string?]{
|
|
|
|
Returns the MIME type associated with @racket[p].
|
|
|
|
The file extension of @racket[p] is extracted and used to look up the
|
|
corresponding MIME type.
|
|
|
|
If the extension is not recognized, a default MIME type is returned.
|
|
}
|
|
|
|
@section{Mapping}
|
|
|
|
The module contains a predefined mapping from file extensions to MIME types.
|
|
|
|
Typical mappings include:
|
|
|
|
@itemlist[#:style 'compact
|
|
@item{@tt{.html} → @tt{text/html}}
|
|
@item{@tt{.css} → @tt{text/css}}
|
|
@item{@tt{.js} → @tt{application/javascript}}
|
|
@item{@tt{.json} → @tt{application/json}}
|
|
@item{@tt{.png} → @tt{image/png}}
|
|
@item{@tt{.jpg}, @tt{.jpeg} → @tt{image/jpeg}}
|
|
@item{@tt{.svg} → @tt{image/svg+xml}}]
|
|
|
|
The exact mapping is defined in the source code and can be extended if needed.
|
|
|
|
@section{Notes}
|
|
|
|
The returned MIME type is always a string suitable for use in HTTP response
|
|
headers.
|
|
|
|
File extensions are interpreted case-insensitively.
|