The Content-Type header
When AMD recognizes a supported file, it automatically defines it as a media file based on the Content-Type header that’s included in the response. You can change this.
The default approach applies a fixed content type value via metadata, in an attempt to optimize the delivery of media assets via AMD. Since AMD sets this to a standard, fixed value, it doesn't have to read from the Content-Type header on your origin and generate individual Content-Type headers in the responses. Reading from this header with each request could delay delivery a negligible amount of time.
What if you need to customize your Content-Type header in your responses? A typical Content-Type header indicates the original media type of the requested resource. You can get this header to report this in the response, or you can apply other unique information. You do this by including optional behaviors in your AMD property and configuring them appropriately.
The Modify Outgoing Response Header behavior
You can manually set the desired Content-Type using the Modify Outgoing Response Header (MORH) behavior.
-
Click Add Rule. The MORH behavior isn’t supported for use in the Default Rule.
-
Select Blank Rule Template from the list.
-
Click Add Match.
-
In Criteria, set the "If" match parameters to:
- File Extension, Filename, Path, Hostname, or Variable Match
- is one of
-
Input an applicable value in the Select Items field, based on the type of match criteria you selected. For example, if you set this to Filename, and you want to target your manifest file, you could input “manifest.m3u8.”
-
Click Add Behavior.
-
In Search available behaviors, type "modify" and select Modify Outgoing Response Header from the list.
-
Click Insert Behavior.
-
Set Action to Modify and Select Header Name to Content-Type.
-
In Header Value, enter what you want to be included in the Content-Type header in the response. For example, if you’ve set this rule up to look for requests for your manifest.m3u8 file, you could set this to return the MIME type for a
ts
segment,video/mp2t
. -
Repeat this process to add more rules for different content types. Each specific content type needs to be set up in its own rule.
Example use case
In this example, we'll set up three separate rules to report three separate content types.
Before you begin
This process uses the hostname match criteria in one of the rules. Before we can apply this, we need to define a separate property hostname in an AMD property. So, we’d need two property hostnames set up for this scenario:
-
The primary property hostname. Requests to the URL defined here will be resolved to handle the majority of the requests. We’re using the URL, “baseball-videos.com” for this property hostname. The first two rules in this example will apply to requests from this hostname.
-
The secondary property hostname. This hostname is used to handle requests for specific media. We’ll apply it in a separate rule to manage the content-type response via the MORH behavior. We’ve used “baseball-videos-legacy-windows.com” for this property hostname.
Set up process
-
Click Add Rule.
-
Click Add Match and set the criteria to File Extension and is one of.
-
Use the Select Items field to select the file extension. We'll pick ts for an MPEG transport stream.
-
Click Add Behavior.
-
In Search available behaviors, type "modify" and select Modify Outgoing Response Header from the list.
-
Click Insert Behavior.
-
Set Action to Modify and set Select Header Name to Content-Type.
-
Set the New Header Value. The default MIME type for ts files is
video/mp2t
, so we input that here.
If you don't see the file type you want in the Select Items drop-down, you can manually input the desired file extension without the period. You can also use a custom New Header Value, if you don't want to enter the default MIME type for a file format. What you input will be included in the Content-Type header in the response.
-
Click Add Rule again, to add another rule beneath the one you just set up.
-
Click Add Match and set the criteria to File Extension and is one of.
-
Use the Select Items field to select the file extension. We'll pick m4v for an MPEG-4 video container format.
-
Repeat steps 4 - 7 to add the Modify Outgoing Response Header behavior to this rule.
-
Set the New Header Value. The default MIME type for
m4v
files isvideo/mp4
, so we input that here.
-
Click Add Rule again.
-
Click Add Match and set the criteria to Hostname and is one of.
-
Use the Select Items field to specify the hostname. We’ve set up the property hostname using the URL, “baseball-videos-legacy-windows.com.” So, we set that here.
-
Repeat steps 4 - 7 to add the Modify Outgoing Response Header behavior to this rule.
-
Set the New Header Value. End users targeting this URL are requesting Windows Advanced Systems Format video, including
asf
,wma
, andwmv
format media. So, we’ll set this to the default MIME type for these formats, which isvideo/ms-asf
.
You can continue to add more rules to your property in this fashion and customize them for other file types. When a request comes in that matches any of these criteria, the Content-Type header will be returned in the response and look something like this:
Requests for a .ts segment file
Content-Type: video/mp2t
Requests for an .m4v file
Content-Type: video/mp4
Request to the hostname, baseball-videos-legacy-windows.com
Content-Type: video/ms-asf
Existing AMD properties and MORH
With past versions of the MORH behavior, you couldn't modify the Content-Type header in your AMD property. You got an error message when you tried to do so.
Now, you can update an existing AMD property to a new version and add this support.
The Default CORS Policy rule
This rule is added by default in your AMD property. It contains several instances of the same Modify Outgoing Response Header behavior, pre-populated with values to optimize delivery. Akamai recommends that you leave this rule in your property, and don't change its settings.
If you want to manage your Content-Type header, use a different rule, as described in the previous sections.
Updated over 1 year ago