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
static func == (HTTPMediaType, HTTPMediaType) -> BoolSeeEquatable.
Initializers
init(type: String, subType: String, parameters: [String : String])Create a newMediaType.
Instance Properties
var description: StringSeeCustomStringConvertible.var parameters: [String : String]TheMediaType’s metadata. Zero or more key/value pairs.var subType: StringTheMediaType’s specific type. Usually a unique string.var type: StringTheMediaType’s discrete or composite type. Usually one of the following.
Instance Methods
func hash(into: inout Hasher)SeeHashable.func serialize() -> StringConverts thisMediaTypeinto its string representation.
Type Properties
static let any: HTTPMediaTypeAny media type (/).static let audio: HTTPMediaTypeBasic audio.static let avi: HTTPMediaTypeAVI video.static let avif: HTTPMediaTypeAVIF image.static let binary: HTTPMediaTypeBinary data.static let bzip2: HTTPMediaTypeBzip2 file.static let css: HTTPMediaTypeCSS media type.static let dtd: HTTPMediaTypeDTD media type.static let formData: HTTPMediaTypeMultipart encoded form data.static let gif: HTTPMediaTypeGIF image.static let gzip: HTTPMediaTypeGzip file.static let heic: HTTPMediaTypeHEIC (HEVC in HEIF) imagestatic let html: HTTPMediaTypeHTML media type.static let jpeg: HTTPMediaTypeJPEG image.static let json: HTTPMediaTypeJSON media type.static let jsonAPI: HTTPMediaTypeJSON API media type.static let jsonSequence: HTTPMediaTypeJSON sequence media type.static let jxl: HTTPMediaTypeJPEG XL image.static let midi: HTTPMediaTypeMIDI audio.static let mp3: HTTPMediaTypeMP3 audio.static let mpeg: HTTPMediaTypeMPEG video.static let multipart: HTTPMediaTypeMixed multipart encoded data.static let ogg: HTTPMediaTypeOGG audio.static let pdf: HTTPMediaTypePDF data.static let plainText: HTTPMediaTypePlain text media type.static let png: HTTPMediaTypePNG image.static let svg: HTTPMediaTypeSVG image.static let tar: HTTPMediaTypetar file.static let tiff: HTTPMediaTypeTIFF image.static let urlEncodedForm: HTTPMediaTypeURL encoded form media type.static let wave: HTTPMediaTypeWave audio.static let webp: HTTPMediaTypeWebP image.static let xml: HTTPMediaTypeXML media type.static let zip: HTTPMediaTypeZip file.
Type Methods
static func fileExtension(String) -> HTTPMediaType?Creates aMediaTypefrom a file extension, if possible.static func formData(boundary: String) -> HTTPMediaType
Relationships
Conforms To
Swift.CustomStringConvertibleSwift.EquatableSwift.HashableSwift.SendableSwift.SendableMetatype