MIME Headers¶
The Traffic Server **MIME header functions ** enable you to retrieve and modify information about HTTP MIME fields.
An HTTP request or response consists of a header, body, and trailer. The HTTP header contains a request (or response) line and a MIME header. A MIME header is composed of zero or more MIME fields. A MIME field is composed of a field name, a colon, and zero or more field values (values in a field are separated by commas).
In the example below: Foo
is the MIME field name, bar
is the
first MIME field value, and car
is the second MIME field value.
Foo: bar, car
The following example is an augmented Backus-Naur Form (BNF) for the
form of a MIME header - it specifies exactly what was described above. A
header consists of zero or more fields that contain a name,
separating colon, and zero or more values. A name or value is
simply a string of tokens that is potentially zero length; a token
is any character except certain control characters and separators (such
as colons). For the purpose of retrieving a field, field names are not
case-sensitive; therefore, the field names Foo
, foo
and fOO
are all equivalent.
MIME-header = *MIME-field
MIME-field = field-name ":" #field-value
field-name = *token
field-value = *token
The MIME header data structure is a parsed version of a standard
Internet MIME header. The MIME header data structure is similar to the
URL data structure (see URLs). The actual data is stored in a
marshal buffer; the MIME header functions operate on a marshal buffer
and a location (TSMLoc
) within the buffer.
After a call to TSMimeHdrFieldDestroy
or TSMimeHdrFieldRemove
is
made, you must deallocate the TSMLoc
handle with a call to
TSHandleMLocRelease
. You do not need to deallocate a NULL
handles.
For example: if you call TSMimeHdrFieldValueStringGet
to get the value of
the content type field and the field does not exist, then it returns
TS_NULL_MLOC
. In such a case, you wouldn’t need to deallocate the handle
with a call to TSHandleMLocRelease
.
The location (TSMLoc
) in the MIME header
functions can be either an HTTP header location or
a MIME header location. If an HTTP header location is passed to these
functions, then the system locates the MIME header associated with that
HTTP header and executes the corresponding MIME header operations
specified by the functions (see the example in the description of
TSMimeHdrCopy()
).
Note: MIME headers may contain more than one MIME field with the
same name. Previous versions of Traffic Server joined multiple fields
with the same name into one field with composite values, but this
behavior came at a performance cost and caused compatibility issues with
older clients and servers. Hence, the current version of Traffic Server
does not coalesce duplicate fields. Correctly-behaving plugins should
check for the presence of duplicate fields and iterate over the
duplicate fields by using TSMimeHdrFieldNextDup
.
To facilitate fast comparisons and reduce storage size, Traffic Server defines several pre-allocated field names. These field names correspond to the field names in HTTP and NNTP headers.
- “Accept”
-
const char *
TS_MIME_FIELD_ACCEPT
¶
-
int
TS_MIME_LEN_ACCEPT
¶
-
const char *
- “Accept-Charset”
-
const char *
TS_MIME_FIELD_ACCEPT_CHARSET
¶
-
int
TS_MIME_LEN_ACCEPT_CHARSET
¶
-
const char *
- “Accept-Encoding”
-
const char *
TS_MIME_FIELD_ACCEPT_ENCODING
¶
-
int
TS_MIME_LEN_ACCEPT_ENCODING
¶
-
const char *
- “Accept-Language”
-
const char *
TS_MIME_FIELD_ACCEPT_LANGUAGE
¶
-
int
TS_MIME_LEN_ACCEPT_LANGUAGE
¶
-
const char *
- “Accept-Ranges”
-
const char *
TS_MIME_FIELD_ACCEPT_RANGES
¶
-
int
TS_MIME_LEN_ACCEPT_RANGES
¶
-
const char *
- “Age”
-
const char *
TS_MIME_FIELD_AGE
¶
-
int
TS_MIME_LEN_AGE
¶
-
const char *
- “Allow”
-
const char *
TS_MIME_FIELDALLOW
¶
-
int
TS_MIME_LEN_ALLOW
¶
-
const char *
- “Approved”
-
const char *
TS_MIME_FIELDAPPROVED
¶
-
int
TS_MIME_LEN_APPROVED
¶
-
const char *
- “Authorization”
-
const char *
TS_MIME_FIELDAUTHORIZATION
¶
-
int
TS_MIME_LEN_AUTHORIZATION
¶
-
const char *
- “Bytes”
-
const char *
TS_MIME_FIELDBYTES
¶
-
int
TS_MIME_LEN_BYTES
¶
-
const char *
- “Cache-Control”
-
const char *
TS_MIME_FIELDCACHE_CONTROL
¶
-
int
TS_MIME_LEN_CACHE_CONTROL
¶
-
const char *
- “Client-ip”
-
const char *
TS_MIME_FIELDCLIENT_IP
¶
-
int
TS_MIME_LEN_CLIENT_IP
¶
-
const char *
- “Connection”
-
const char *
TS_MIME_FIELDCONNECTION
¶
-
int
TS_MIME_LEN_CONNECTION
¶
-
const char *
- “Content-Base”
-
const char *
TS_MIME_FIELDCONTENT_BASE
¶
-
int
TS_MIME_LEN_CONTENT_BASE
¶
-
const char *
- “Content-Encoding”
-
const char *
TS_MIME_FIELDCONTENT_ENCODING
¶
-
int
TS_MIME_LEN_CONTENT_ENCODING
¶
-
const char *
- “Content-Language”
-
const char *
TS_MIME_FIELDCONTENT_LANGUAGE
¶
-
int
TS_MIME_LEN_CONTENT_LANGUAGE
¶
-
const char *
- “Content-Length”
-
const char *
TS_MIME_FIELDCONTENT_LENGTH
¶
-
int
TS_MIME_LEN_CONTENT_LENGTH
¶
-
const char *
- “Content-Location”
-
const char *
TS_MIME_FIELDCONTENT_LOCATION
¶
-
int
TS_MIME_LEN_CONTENT_LOCATION
¶
-
const char *
- “Content-MD5”
-
const char *
TS_MIME_FIELDCONTENT_MD5
¶
-
int
TS_MIME_LEN_CONTENT_MD5
¶
-
const char *
- “Content-Range”
-
const char *
TS_MIME_FIELDCONTENT_RANGE
¶
-
int
TS_MIME_LEN_CONTENT_RANGE
¶
-
const char *
- “Content-Type”
-
const char *
TS_MIME_FIELDCONTENT_TYPE
¶
-
int
TS_MIME_LEN_CONTENT_TYPE
¶
-
const char *
- “Control”
-
const char *
TS_MIME_FIELDCONTROL
¶
-
int
TS_MIME_LEN_CONTROL
¶
-
const char *
- “Cookie”
-
const char *
TS_MIME_FIELDCOOKIE
¶
-
int
TS_MIME_LEN_COOKIE
¶
-
const char *
- “Date”
-
const char *
TS_MIME_FIELDDATE
¶
-
int
TS_MIME_LEN_DATE
¶
-
const char *
- “Distribution”
-
const char *
TS_MIME_FIELDDISTRIBUTION
¶
-
int
TS_MIME_LEN_DISTRIBUTION
¶
-
const char *
- “Etag”
-
const char *
TS_MIME_FIELDETAG
¶
-
int
TS_MIME_LEN_ETAG
¶
-
const char *
- “Expect”
-
const char *
TS_MIME_FIELDEXPECT
¶
-
int
TS_MIME_LEN_EXPECT
¶
-
const char *
- “Expires”
-
const char *
TS_MIME_FIELDEXPIRES
¶
-
int
TS_MIME_LEN_EXPIRES
¶
-
const char *
- “Followup-To”
-
const char *
TS_MIME_FIELDFOLLOWUP_TO
¶
-
int
TS_MIME_LEN_FOLLOWUP_TO
¶
-
const char *
- “From”
-
const char *
TS_MIME_FIELDFROM
¶
-
int
TS_MIME_LEN_FROM
¶
-
const char *
- “Host”
-
const char *
TS_MIME_FIELDHOST
¶
-
int
TS_MIME_LEN_HOST
¶
-
const char *
- “If-Match”
-
const char *
TS_MIME_FIELDIF_MATCH
¶
-
int
TS_MIME_LEN_IF_MATCH
¶
-
const char *
- “If-Modified-Since”
-
const char *
TS_MIME_FIELDIF_MODIFIED_SINCE
¶
-
int
TS_MIME_LEN_IF_MODIFIED_SINCE
¶
-
const char *
- “If-None-Match”
-
const char *
TS_MIME_FIELDIF_NONE_MATCH
¶
-
int
TS_MIME_LEN_IF_NONE_MATCH
¶
-
const char *
- “If-Range”
-
const char *
TS_MIME_FIELDIF_RANGE
¶
-
int
TS_MIME_LEN_IF_RANGE
¶
-
const char *
- “If-Unmodified-Since”
-
const char *
TS_MIME_FIELDIF_UNMODIFIED_SINCE
¶
-
int
TS_MIME_LEN_IF_UNMODIFIED_SINCE
¶
-
const char *
- “Keep-Alive”
-
const char *
TS_MIME_FIELDKEEP_ALIVE
¶
-
int
TS_MIME_LEN_KEEP_ALIVE
¶
-
const char *
- “Keywords”
-
const char *
TS_MIME_FIELDKEYWORDS
¶
-
int
TS_MIME_LEN_KEYWORDS
¶
-
const char *
- “Last-Modified”
-
const char *
TS_MIME_FIELDLAST_MODIFIED
¶
-
int
TS_MIME_LEN_LAST_MODIFIED
¶
-
const char *
- “Lines”
-
const char *
TS_MIME_FIELDLINES
¶
-
int
TS_MIME_LEN_LINES
¶
-
const char *
- “Location”
-
const char *
TS_MIME_FIELDLOCATION
¶
-
int
TS_MIME_LEN_LOCATION
¶
-
const char *
- “Max-Forwards”
-
const char *
TS_MIME_FIELDMAX_FORWARDS
¶
-
int
TS_MIME_LEN_MAX_FORWARDS
¶
-
const char *
- “Message-ID”
-
const char *
TS_MIME_FIELDMESSAGE_ID
¶
-
int
TS_MIME_LEN_MESSAGE_ID
¶
-
const char *
- “Newsgroups”
-
const char *
TS_MIME_FIELDNEWSGROUPS
¶
-
int
TS_MIME_LEN_NEWSGROUPS
¶
-
const char *
- “Organization”
-
const char *
TS_MIME_FIELDORGANIZATION
¶
-
int
TS_MIME_LEN_ORGANIZATION
¶
-
const char *
- “Path”
-
const char *
TS_MIME_FIELDPATH
¶
-
int
TS_MIME_LEN_PATH
¶
-
const char *
- “Pragma”
-
const char *
TS_MIME_FIELDPRAGMA
¶
-
int
TS_MIME_LEN_PRAGMA
¶
-
const char *
- “Proxy-Authenticate”
-
const char *
TS_MIME_FIELDPROXY_AUTHENTICATE
¶
-
int
TS_MIME_LEN_PROXY_AUTHENTICATE
¶
-
const char *
- “Proxy-Authorization”
-
const char *
TS_MIME_FIELDPROXY_AUTHORIZATION
¶
-
int
TS_MIME_LEN_PROXY_AUTHORIZATION
¶
-
const char *
- “Proxy-Connection”
-
const char *
TS_MIME_FIELDPROXY_CONNECTION
¶
-
int
TS_MIME_LEN_PROXY_CONNECTION
¶
-
const char *
- “Public”
-
const char *
TS_MIME_FIELDPUBLIC
¶
-
int
TS_MIME_LEN_PUBLIC
¶
-
const char *
- “Range”
-
const char *
TS_MIME_FIELDRANGE
¶
-
int
TS_MIME_LEN_RANGE
¶
-
const char *
- “References”
-
const char *
TS_MIME_FIELDREFERENCES
¶
-
int
TS_MIME_LEN_REFERENCES
¶
-
const char *
- “Referer”
-
const char *
TS_MIME_FIELDREFERER
¶
-
int
TS_MIME_LEN_REFERER
¶
-
const char *
- “Reply-To”
-
const char *
TS_MIME_FIELDREPLY_TO
¶
-
int
TS_MIME_LEN_REPLY_TO
¶
-
const char *
- “Retry-After”
-
const char *
TS_MIME_FIELDRETRY_AFTER
¶
-
int
TS_MIME_LEN_RETRY_AFTER
¶
-
const char *
- “Sender”
-
const char *
TS_MIME_FIELDSENDER
¶
-
int
TS_MIME_LEN_SENDER
¶
-
const char *
- “Server”
-
const char *
TS_MIME_FIELDSERVER
¶
-
int
TS_MIME_LEN_SERVER
¶
-
const char *
- “Set-Cookie”
-
const char *
TS_MIME_FIELDSET_COOKIE
¶
-
int
TS_MIME_LEN_SET_COOKIE
¶
-
const char *
- “Subject”
-
const char *
TS_MIME_FIELDSUBJECT
¶
-
int
TS_MIME_LEN_SUBJECTTS_MIME_LEN_SUBJECT
¶
-
const char *
- “Summary”
-
const char *
TS_MIME_FIELDSUMMARY
¶
-
int
TS_MIME_LEN_SUMMARY
¶
-
const char *
- “TE”
-
const char *
TS_MIME_FIELDTE
¶
-
int
TS_MIME_LEN_TE
¶
-
const char *
- “Transfer-Encoding”
-
const char *
TS_MIME_FIELDTRANSFER_ENCODING
¶
-
int
TS_MIME_LEN_TRANSFER_ENCODING
¶
-
const char *
- “Upgrade”
-
const char *
TS_MIME_FIELDUPGRADE
¶
-
int
TS_MIME_LEN_UPGRADE
¶
-
const char *
- “User-Agent”
-
const char *
TS_MIME_FIELDUSER_AGENT
¶
-
int
TS_MIME_LEN_USER_AGENT
¶
-
const char *
- “Vary”
-
const char *
TS_MIME_FIELDVARY
¶
-
int
TS_MIME_LEN_VARY
¶
-
const char *
- “Via”
-
const char *
TS_MIME_FIELDVIA
¶
-
int
TS_MIME_LEN_VIA
¶
-
const char *
- “Warning”
-
const char *
TS_MIME_FIELDWARNING
¶
-
int
TS_MIME_LEN_WARNING
¶
-
const char *
- “Www-Authenticate”
-
const char *
TS_MIME_FIELDWWW_AUTHENTICATE
¶
-
int
TS_MIME_LEN_WWW_AUTHENTICATE
¶
-
const char *
- “Xref”
-
const char *
TS_MIME_FIELDXREF
¶
-
int
TS_MIME_LEN_XREF
¶
-
const char *
The header field names above are defined in ts.h
as const char*
strings. When Traffic Server sets the name portion of a header field (or
any portion for that matter), it quickly checks to see if the new value
is one of the known values. If it is, then Traffic Server stores a
pointer into a global table instead of storing the known value in the
marshal buffer. The header field names listed above are also pointers
into this table, which enables simple pointer comparison of the value
returned from TSMimeHdrFieldNameGet
with one of the values listed
above. It is recommended that you use the above values when referring to
one of the known header field names to avoid the possibility of a
spelling error.
Traffic Server adds one important feature to MIME fields that you may
not know about: Traffic Server does not print a MIME field if the field
name begins with the ‘@
’ symbol. For example: a plugin can add the
field “@My-Field
” to a header. Even though Traffic Server never
sends that field out in a request to an origin server or in a response
to a client, it can be printed to Traffic Server logs by defining a
custom log configuration file that explicitly logs such fields. This
provides a useful mechanism for plugins to store information about an
object in one of the MIME headers associated with the object.
The MIME header functions are listed below: