Static Hit Plugin

This is a simple plugin to serve static content from the proxy’s local filesystem. It shares some of the same functionality as the healthchecks plugin, but is a remap plugin (thereby making it reloadable). When an object is served by the plugin (not from HTTP cache), the plugin re-reads the current contents of the file containing the object data.

When the plugin is invoked during remapping, if the transaction already has a status other than OK, the plugin will ignore the transaction.

These are the available options for the plugin:

Long Name

One Letter Name

Required?

Has Value?

Description

--file-path

-f

Yes

Yes

File path. If the given path is relative, it is relative to the Traffic Server configuration directory. If the specified file is a directory, it implies --disable-exact, and URL path is appended to this directory path to get the path for the file containing the body. If the specified file is not a directory, it should contain the body.

--mime-type

-m

No

Yes

Defaults to “text/plain”.

--max-age

-a

No

Yes

Defaults to “0”. If the value is not 0, it gives the number of seconds the static body will remain fresh when cache. (Including in the proxy’s cache, if enabled.)

--failure-code

-c

No

Yes

Defaults to “404” (NOT FOUND). This response status will be returned if the file which should contain the body does not exist. This option is particularly useful when --file-path specifies a directory.

--success-code

-s

No

Yes

Defaults to “200” (OK). This is the response status when the static object is successfully returned in the transaction response.

--disable-exact

-d

No

No

Disable “exact” URL match. “Exact” match, for this plugin, means the URL must not include a path.

When using long option names, the value can be specified by appending = and then the value. @pparam=--max-age=5 for example. Otherwise, the value must be specified as the next pparam. @pparam=-a @pparam=5 for example.

When exact match is enabled, if the request URL has a path, a response with NOT FOUND status will be sent.

Mime Headers in Responses with OK/200 Status

  1. Content-Type. The value given with the --mime-type parameter, or its default value.

  2. Content-Length.

  3. Cache-Control. If --max-age is 0, the value will be “no-cache”. Otherwise, the value will be “max-age=d”, where d stands for the value given with the --max-age parameter.

  4. if --max-age is not 0, Last-Modified is present, and gives the time the static body was last cached.

Metrics

The plugin publishes the following metrics:

Name

Description

statichit.response_bytes

The total number of bytes emitted

statichit.response_count

The number of HTTP responses generated by the plugin

remap.config Examples:

Serve a request for /internal/healthcheck with the contents of the file located at /var/run/trafficserver/healthcheck.txt. If the file is present, send with a Mime-type of text/plain. Also set the Cache-Control: header to no-cache.

map /internal/healthcheck \
http://127.0.0.1 \
@plugin=statichit.so @pparam=--file-path=/var/run/trafficserver/healthcheck.txt \
@pparam=--mime-type=text/plain \
@pparam=--success-code=200 \
@pparam=--failure-code=403 \
@pparam=--max-age=0 \
@pparam=--disable-exact

Serve a request for content.example.com/content_xyz.txt with the contents of the file content_bodies/content_xyz.txt under the Traffic Server configuration file directory (as content_bodies is meant to imply a directory in this example).

map http://content.example.com/content_xyz.txt \
http://127.0.0.1 \
@plugin=statichit.so @pparam=--file-path=content_bodies \
@pparam=--failure-code=404 \
@pparam=--max-age=604800

Serve a request for content.example.com/content_abc.json with the contents of the file content_bodies/content_xyz.txt under the Traffic Server configuration file directory (as content_bodies is meant to imply a directory in this example) with a mime-type of application/json. Set cache-control to have a max-age of 7 days (604800 seconds).

map http://content.example.com/content_abc.json \
http://127.0.0.1 \
@plugin=statichit.so @pparam=--file-path=content_bodies \
@pparam=--mime-type=application/json \
@pparam=--max-age=604800

NOTE: The remap origin is never contacted because this plugin intercepts the request and acts as the origin server. For that reason, the origin specification must be syntactically valid and resolvable in DNS.