Mod http cache

From FreeSWITCH Wiki

Revision as of 00:45, 25 April 2012 by Crienzo (Talk | contribs)
Jump to: navigation, search

Contents

mod_http_cache (HTTP GET files with caching)

mod_http_cache allows one to make a HTTP GET request to cache a document. The primary use case is to download and cache audio files from a web server.

mod_http_cache will only respect the max-age cache-control directive to determine when a cached file becomes stale.

mod_httapi is also available which offers HTTP file caching via a file interface.

Installing

To use mod_http_cache:

Tell FreeSWITCH to compile in this module by editing modules.conf in /usr/src/freeswitch/trunk and adding:

 applications/mod_http_cache

Now go recompile FreeSWITCH.

make
make install

Tell FreeSWITCH to actually use the module when running by adding the module to modules.conf.xml in /usr/local/freeswitch/conf/autoload_configs:

<load module="mod_http_cache"/>

For HTTPS support, grab the latest CA certs from http://curl.haxx.se/ca/cacert.pem and install in /usr/local/freeswitch/conf. An older copy is also available in freeswitch/src/mod/applications/mod_http_cache/conf/cacert.pem.

Configuration

The conf/autoload_configs/http_cache.conf.xml file contains the configuration.

<configuration name="http_cache.conf" description="HTTP GET cache">
  <settings>
    <!-- maximum size of cache -->
    <param name="max-urls" value="10000"/>
    <!-- location of cached files -->
    <param name="location" value="$${base_dir}/http_cache"/>
    <!-- if not specified by cache-control max-age directive, this value will be used
         to expire cached files -->
    <param name="default-max-age" value="86400"/>
    <!-- size of the prefetch thread pool -->
    <param name="prefetch-thread-count" value="8"/>
    <!-- size of the prefetch request queue -->
    <param name="prefetch-queue-size" value="100"/>
    <!-- absolute path to CA bundle file -->
    <param name="ssl-cacert" value="$${base_dir}/conf/cacert.pem"/>
    <!-- verify certificates -->
    <param name="ssl-verifypeer" value="true"/>
    <!-- verify host name matches certificate -->
    <param name="ssl-verifyhost" value="true"/>
  </settings>
</configuration>

API

http_prefetch

Download a URL to the cache in a background thread. Does not wait for the download to finish.

  http_prefetch http://myserver.yo/media/hello_world.wav

http_get

Download a document to the cache. Returns the name of the cached file suitable for use by FreeSWITCH APPs or "-ERR" on error.

   http_get http://myserver.yo/media/hello_world.wav

http_tryget

Same as http_get except if the document is missing from the cache or stale, "-ERR download" is returned. i.e. this API call checks the cache only. "-ERR" is returned on all other errors.

  http_tryget http://myserver.yo/media/hello_world.wav

http_put

PUT a file. This can be used to PUT a file like a session recording to a webserver.

  http_put http://user:password@myserver.yo/recordings/1df4a12708bcea.wav /tmp/1df4a12708bcea.wav

http_clear_cache

Empty the cache.

  http_clear_cache

Examples

Play a .wav file hosted by a webserver

While this example below will work, it is probably best to download all the .wav files needed by a call in a background thread early in the call using http_prefetch. Subsequent calls to http_get will then just grab the cached file. That way, delays in downloading will be less likely to cause pauses in playback.

Dialplan XML

<action application="playback" data="${http_get(http://myserver.yo/media/hello_world.wav)}"/>

Play a .wav file hosted by a webserver to a single conference member

This example uses the "expand" API call to resolve the channel variables and to execute http_get. This would be executed by an external process controlling the call over ESL or the raw event socket.

expand uuid:12345 conference my_awesome_conference_123 play ${http_get(http://myserver.yo/media/hello_world.wav)} ${conference_member_id}
Personal tools

Community
Support FreeSWITCH