Configuration: Prefetching of content

Origin configuration

Apache

Unified Origin provides by default the Link Header response for media requests. The following is an example of the Link Header response by Unified Origin.

The HTTP request /presentation.ism/QualityLevels(652000)/Fragments(video=0) automatically generates a (relative) HTTP Link header pointing to the following media segment:

Link: <Fragments(video=4800000)>; rel="next"

Note

For more details of the supported HTTP media requests of the Link Header, please refer to Prefetch Headers.

Origin shield configuration

Nginx

Nginx provides njs module that can extend the functionality of Nginx by manipulating response headers, and allowing to write asynchronous content handlers and filters. This module provides flexibility to implement the prefetch of the next media object. You can use the Link Header which Unified Streaming provides in VoD and Live use cases.

In Nginx web server you can prefetch media content content by using njs subrequest module. When using this module is important to configure it by increasing the value of subrequest_output_buffer_size in the configuration file. Usually this value needs to be higher than the size of the maximum bitrate segments on the streaming event.

Varnish Cache

Varnish Cache six plus offers module http which can be used to generated prefetch of media objects. The following is an example on how to prefetch the next available media segment using Varnish Cache six plus and the Link Header response from Unified Origin.

sub vcl_backend_response {
    // NOTE: The following condition will only be executed if the client's
    // request is not yet in cache.

    // Extract the Link Header from current request
    if (beresp.http.Link ~ "<.+>.*(prefetch|next)")
    {
        // Pull out the Link URL
        set bereq.http.X-link = regsub(beresp.http.Link, "^.*<([^>]*)>.*$", "\1");

        if (str.contains(bereq.http.X-prefetch, "dash"))
        {
            set bereq.http.X-prefetch = regsub(
                bereq.http.X-prefetch, "(dash\/.*.dash)",
                "dash/" + bereq.http.X-link);
        }
        elseif (str.contains(bereq.http.X-prefetch, "hls")) {
            set bereq.http.X-prefetch = regsub(
                bereq.http.X-prefetch, "(hls\/.*.[ts|m4s])",
                "hls/" + bereq.http.X-link);
        }
        // NOTE: we are not taking in consideration the bitrate in HSS,
        // only the fragment number
        elseif (str.contains(bereq.http.X-prefetch, "QualityLevels")) {
            set bereq.http.X-prefetch = regsub(
                bereq.http.X-prefetch,
                "(Fragments\([video|audio].*\))", bereq.http.X-link);
        }
        else {
            std.log("Link Header not supported");
            // Do not set any bereq.http.X-prefetch
        }

        // Generate the request to the backend for the next available media object
        if (bereq.http.X-prefetch) {
            // Prefetch the Link URL back thru Varnish
            http.init(0);
            http.req_copy_headers(0);
            http.req_set_url(0, bereq.http.X-prefetch);
            http.req_send_and_finish(0);
        }

    }
}