Home

Traffic Server Software Developers Kit

MIME Headers

The Traffic Server API 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 consists of 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 (the 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 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 consist of a name, a 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).

MIME-header = *MIME-field
MIME-field = field-name ":" #field-value
field-name = *token
field-value = *token

For the purposes of retrieving a field, field names are not case-sensitive; ergo, the field names Foo, foo and fOO are all equivalent.

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 and the MIME header functions operate on a marshal buffer and a location (INKMLoc) within the buffer.

After a call to INKMimeHdrFieldDestroy, INKMimeHdrFieldRemove, or INKUrlDestroy is made, you must deallocate the INKMLoc handle with a call to INKHandleMLocRelease. You do not need to deallocate a NULL handles. For example: if you called INKMimeHdrFieldValueStringGet to get the value of the content type field and the field does not exist, then it returns INK_NULL_MLOC. In such a case, you wouldn't need to deallocate the handle with a call to INKHandleMLocRelease.

The location (INKMLoc) in the following MIME header functions can be either a HTTP header location or a MIME header location. If an HTTP header location is passed to these function, then the system locates the MIME header associated with this HTTP header and then executes the corresponding MIME header operations specified by the functions (see the example in the description of INKMimeHdrCopy).

MIME headers may contain more than one MIME field with the same name. While previous versions of Traffic Server joined multiple fields with the same name into one field with composite values, this behavior comes at a performance cost and causes compatability issues with older clients and servers. Future versions of Traffic Server will cease coalescing duplicate fields. Correctly-behaving plugins should check for the presence of duplicate fields, and iterate over the duplicate fields, by using INKMimeHdrFieldNextDup.

To facilitate fast comparisons and to reduce storage size, Traffic Server defines several pre-allocated field names. These field names correspond to field names found in HTTP and NNTP headers.

Traffic Server pre-allocated field names HTTP and NNTP header field names Associated string lengths
INK_MIME_FIELD_ACCEPT "Accept" INK_MIME_LEN_ACCEPT
INK_MIME_FIELD_ACCEPT_CHARSET “Accept-Charset" INK_MIME_LEN_ACCEPT_CHARSET
INK_MIME_FIELD_ACCEPT_ENCODING "Accept-Encoding" INK_MIME_LEN_ACCEPT_ENCODING
INK_MIME_FIELD_ACCEPT_LANGUAGE "Accept-Language" INK_MIME_LEN_ACCEPT_LANGUAGE
INK_MIME_FIELD_ACCEPT_RANGES "Accept-Ranges" INK_MIME_LEN_ACCEPT_RANGES
INK_MIME_FIELD_AGE "Age" INK_MIME_LEN_AGE
INK_MIME_FIELD_ALLOW "Allow" INK_MIME_LEN_ALLOW
INK_MIME_FIELD_APPROVED “Approved" INK_MIME_LEN_APPROVED
INK_MIME_FIELD_AUTHORIZATION "Authorization" INK_MIME_LEN_AUTHORIZATION
INK_MIME_FIELD_BYTES "Bytes" INK_MIME_LEN_BYTES
INK_MIME_FIELD_CACHE_CONTROL "Cache-Control" INK_MIME_LEN_CACHE_CONTROL
INK_MIME_FIELD_CLIENT_IP "Client-ip" INK_MIME_LEN_CLIENT_IP
INK_MIME_FIELD_CONNECTION "Connection" INK_MIME_LEN_CONNECTION
INK_MIME_FIELD_CONTENT_BASE "Content-Base" INK_MIME_LEN_CONTENT_BASE
INK_MIME_FIELD_CONTENT_ENCODING "Content-Encoding" INK_MIME_LEN_CONTENT_ENCODING
INK_MIME_FIELD_CONTENT_LANGUAGE "Content-Language" INK_MIME_LEN_CONTENT_LANGUAGE
INK_MIME_FIELD_CONTENT_LENGTH "Content-Length" INK_MIME_LEN_CONTENT_LENGTH
INK_MIME_FIELD_CONTENT_LOCATION "Content-Location" INK_MIME_LEN_CONTENT_LOCATION
INK_MIME_FIELD_CONTENT_MD5 "Content-MD5" INK_MIME_LEN_CONTENT_MD5
INK_MIME_FIELD_CONTENT_RANGE "Content-Range" INK_MIME_LEN_CONTENT_RANGE
INK_MIME_FIELD_CONTENT_TYPE "Content-Type" INK_MIME_LEN_CONTENT_TYPE
INK_MIME_FIELD_CONTROL "Control" INK_MIME_LEN_CONTROL
INK_MIME_FIELD_COOKIE "Cookie" INK_MIME_LEN_COOKIE
INK_MIME_FIELD_DATE "Date" INK_MIME_LEN_DATE
INK_MIME_FIELD_DISTRIBUTION "Distribution" INK_MIME_LEN_DISTRIBUTION
INK_MIME_FIELD_ETAG "Etag" INK_MIME_LEN_ETAG
INK_MIME_FIELD_EXPECT "Expect" INK_MIME_LEN_EXPECT
INK_MIME_FIELD_EXPIRES "Expires" INK_MIME_LEN_EXPIRES
INK_MIME_FIELD_FOLLOWUP_TO "Followup-To" INK_MIME_LEN_FOLLOWUP_TO
INK_MIME_FIELD_FROM "From" INK_MIME_LEN_FROM
INK_MIME_FIELD_HOST "Host" INK_MIME_LEN_HOST
INK_MIME_FIELD_IF_MATCH "If-Match" INK_MIME_LEN_IF_MATCH
INK_MIME_FIELD_IF_MODIFIED_SINCE "If-Modified-Since'' INK_MIME_LEN_IF_MODIFIED_SINCE
INK_MIME_FIELD_IF_NONE_MATCH "If-None-Match'' INK_MIME_LEN_IF_NONE_MATCH
INK_MIME_FIELD_IF_RANGE "If-Range'' INK_MIME_LEN_IF_RANGE
INK_MIME_FIELD_IF_UNMODIFIED_SINCE "If-Unmodified-Since'' INK_MIME_LEN_IF_UNMODIFIED_SINCE
INK_MIME_FIELD_KEEP_ALIVE "Keep-Alive'' INK_MIME_LEN_KEEP_ALIVE
INK_MIME_FIELD_KEYWORDS "Keywords'' INK_MIME_LEN_KEYWORDS
INK_MIME_FIELD_LAST_MODIFIED "Last-Modified'' INK_MIME_LEN_LAST_MODIFIED
INK_MIME_FIELD_LINES "Lines'' INK_MIME_LEN_LINES
INK_MIME_FIELD_LOCATION "Location'' INK_MIME_LEN_LOCATION
INK_MIME_FIELD_MAX_FORWARDS "Max-Forwards'' INK_MIME_LEN_MAX_FORWARDS
INK_MIME_FIELD_MESSAGE_ID "Message-ID'' INK_MIME_LEN_MESSAGE_ID
INK_MIME_FIELD_NEWSGROUPS "Newsgroups'' INK_MIME_LEN_NEWSGROUPS
INK_MIME_FIELD_ORGANIZATION "Organization'' INK_MIME_LEN_ORGANIZATION
INK_MIME_FIELD_PATH "Path'' INK_MIME_LEN_PATH
INK_MIME_FIELD_PRAGMA "Pragma'' INK_MIME_LEN_PRAGMA
INK_MIME_FIELD_PROXY_AUTHENTICATE "Proxy-Authenticate'' INK_MIME_LEN_PROXY_AUTHENTICATE
INK_MIME_FIELD_PROXY_AUTHORIZATION "Proxy-Authorization'' INK_MIME_LEN_PROXY_AUTHORIZATION
INK_MIME_FIELD_PROXY_CONNECTION "Proxy-Connection'' INK_MIME_LEN_PROXY_CONNECTION
INK_MIME_FIELD_PUBLIC "Public'' INK_MIME_LEN_PUBLIC
INK_MIME_FIELD_RANGE "Range'' INK_MIME_LEN_RANGE
INK_MIME_FIELD_REFERENCES "References'' INK_MIME_LEN_REFERENCES
INK_MIME_FIELD_REFERER "Referer'' INK_MIME_LEN_REFERER
INK_MIME_FIELD_REPLY_TO "Reply-To'' INK_MIME_LEN_REPLY_TO
INK_MIME_FIELD_RETRY_AFTER "Retry-After'' INK_MIME_LEN_RETRY_AFTER
INK_MIME_FIELD_SENDER "Sender'' INK_MIME_LEN_SENDER
INK_MIME_FIELD_SERVER "Server'' INK_MIME_LEN_SERVER
INK_MIME_FIELD_SET_COOKIE "Set-Cookie'' INK_MIME_LEN_SET_COOKIE
INK_MIME_FIELD_SUBJECT "Subject'' INK_MIME_LEN_SUBJECTINK_MIME_LEN_SUBJECT
INK_MIME_FIELD_SUMMARY "Summary'' INK_MIME_LEN_SUMMARY
INK_MIME_FIELD_TE "TE'' INK_MIME_LEN_TE
INK_MIME_FIELD_TRANSFER_ENCODING "Transfer-Encoding'' INK_MIME_LEN_TRANSFER_ENCODING
INK_MIME_FIELD_UPGRADE "Upgrade'' INK_MIME_LEN_UPGRADE
INK_MIME_FIELD_USER_AGENT "User-Agent'' INK_MIME_LEN_USER_AGENT
INK_MIME_FIELD_VARY "Vary'' INK_MIME_LEN_VARY
INK_MIME_FIELD_VIA "Via'' INK_MIME_LEN_VIA
INK_MIME_FIELD_WARNING "Warning'' INK_MIME_LEN_WARNING
INK_MIME_FIELD_WWW_AUTHENTICATE "Www-Authenticate'' INK_MIME_LEN_WWW_AUTHENTICATE
INK_MIME_FIELD_XREF "Xref'' INK_MIME_LEN_XREF

The header field names above are defined in InkAPI.h as const char* strings. When Traffic Server sets the name portion of a header field (or any portion for that matter), it makes a quick check to see if the new value is one of the known values. If it is, then it 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 allows simple pointer comparison of the value returned from INKMimeHdrFieldNameGet with one of the values listed above. It is also 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 in Traffic Server logs by defining a custom log config 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: