Structure
HTTPMediaType
Represents an encoded data-format, used in HTTP, HTML, email, and elsewhere.
struct HTTPMediaType
Overview
text/plain
application/json; charset=utf8
Description from rfc2045:
In general, the top-level media type is used to declare the general
type of data, while the subtype specifies a specific format for that
type of data. Thus, a media type of "image/xyz" is enough to tell a
user agent that the data is an image, even if the user agent has no
knowledge of the specific image format "xyz". Such information can
be used, for example, to decide whether or not to show a user the raw
data from an unrecognized subtype -- such an action might be
reasonable for unrecognized subtypes of text, but not for
unrecognized subtypes of image or audio. For this reason, registered
subtypes of text, image, audio, and video should not contain embedded
information that is really of a different type. Such compound
formats should be represented using the "multipart" or "application"
types.
Simplified format:
mediaType := type "/" subtype *(";" parameter)
; Matching of media type and subtype
; is ALWAYS case-insensitive.
type := token
subtype := token
parameter := attribute "=" value
attribute := token
; Matching of attributes
; is ALWAYS case-insensitive.
token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
or tspecials>
value := token
; token MAY be quoted
tspecials := "(" / ")" / "<" / ">" / "@" /
"," / ";" / ":" / "\" / <">
"/" / "[" / "]" / "?" / "="
; Must be in quoted-string,
; to use within parameter values
Topics
Operators
==(_:_:)SeeEquatable.
Initializers
init(type:subType:parameters:)Create a newMediaType.
Instance Properties
descriptionSeeCustomStringConvertible.parametersTheMediaType’s metadata. Zero or more key/value pairs.subTypeTheMediaType’s specific type. Usually a unique string.typeTheMediaType’s discrete or composite type. Usually one of the following.
Instance Methods
hash(into:)SeeHashable.serialize()Converts thisMediaTypeinto its string representation.
Type Properties
anyAny media type (/).audioBasic audio.aviAVI video.avifAVIF image.binaryBinary data.bzip2Bzip2 file.cssCSS media type.dtdDTD media type.formDataMultipart encoded form data.gifGIF image.gzipGzip file.heicHEIC (HEVC in HEIF) imagehtmlHTML media type.jpegJPEG image.jsonJSON media type.jsonAPIJSON API media type.jsonSequenceJSON sequence media type.jxlJPEG XL image.midiMIDI audio.mp3MP3 audio.mpegMPEG video.multipartMixed multipart encoded data.oggOGG audio.pdfPDF data.plainTextPlain text media type.pngPNG image.svgSVG image.tartar file.tiffTIFF image.urlEncodedFormURL encoded form media type.waveWave audio.webpWebP image.xmlXML media type.zipZip file.
Type Methods
fileExtension(_:)Creates aMediaTypefrom a file extension, if possible.formData(boundary:)
Relationships
Conforms To
Swift.CustomStringConvertibleSwift.EquatableSwift.HashableSwift.SendableSwift.SendableMetatype