1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
.. _admin-plugins-statichit:
.. include:: ../../common.defs
Static Hit Plugin
*****************
.. Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
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 Required? Has Description
Letter Value?
Name
================= ======= ========= ====== ==============
\-\-file-path -f Yes Yes File path. If the given path is relative, it is relative to the |TS|
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
============================================
#. Content-Type. The value given with the \-\-mime-type parameter, or its default value.
#. Content-Length.
#. 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.
#. 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 |TS| 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 |TS| 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.
|