Configuration: HTTP response Headers

Origin configuration

Apache

The following is an example on how to use Apache web server module mod_deflate as it is described in Origin best practices. In this case Apache 2 web server will compress the media playlist based on the request Accept-Encoding Header by the media player or CDN.

<IfModule deflate_module>
    AddOutputFilterByType DEFLATE \
    application/vnd.apple.mpegurl \
    application/dash+xml \
    text/xml \
    application/f4m+xml

    Header append Vary Accept-Encoding env=!dont-vary
</IfModule>

Note

Unified Origin will compress previous Content-Type files using gzip compression only if the request Header contains Accept-Encoding: gzip. Otherwise, Unified Origin will return an uncompressed file.

Origin shield configuration

Nginx

By default, Nginx respects the response Vary: Accept-Encoding Header provided by Unified Origin and which has been explained in previous section. In this case Nginx will save two different versions of the media playlist upon request.

Varnish Cache

Varnish Cache by default will store one single object in cache regardless of the Vary: Accept-Encoding Header response provided by Unified Origin. If the player/CDN requested an uncompressed response, Varnish will on-the-fly decompressing the cached object and will deliver it to the player/CDN. If your CDN caches objects using the ETag Header is necessary to remove the postfix -gzip from the uncompressed response generated by Varnish Cache. The following VCL configuration is an example for the normalization of different Accept-Encoding values and the update of the ETag Header after Varnish decompressed the file.

vcl 4.0;
import http;
import std;


sub vcl_recv {
    if (req.http.Accept-Encoding) {
        if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
            # No point in compressing these
            unset req.http.Accept-Encoding;
        } elsif (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding = "gzip";
        } elsif (req.http.Accept-Encoding ~ "deflate") {
            set req.http.Accept-Encoding = "deflate";
        } else {
            # unknown algorithm
            unset req.http.Accept-Encoding;
        }
    }
}

sub vcl_deliver {
    # We make sure that the object in cache has gzip compression.
    # Also, we remove the `-gzip` postfix from the Etag if the player
    # did not contain a Accept-Encoding request Header.
    if (!req.http.Accept-Encoding && resp.http.Content-Encoding == "gzip"
        && resp.http.ETag ~ "^W\/\x22.+-gzip\x22$")
    {
        if (resp.http.Content-Type == "application/vnd.apple.mpegurl" ||
            resp.http.Content-Type == "application/dash+xml" ||
            resp.http.Content-Type == "text/xml" ||
            resp.http.Content-Type == "application/f4m+xml")
        {
            set resp.http.ETag = regsub(
                resp.http.ETag, "^W\/\x22(.+)-gzip\x22$", {""\1""}
            );
        }
    }
}