TSAPI(3ts) | Apache Traffic Server | TSAPI(3ts) |
TSAPI - introduction to the Apache Traffic Server API
#include <ts/ts.h> #include <ts/remap.h>
The Apache Traffic Server API enables you to create plugins, using the C programming language, that customize the behavior of your Traffic Server installation.
Traffic Server enables sophisticated caching and processing of web-related traffic, such as DNS and HTTP requests and responses. Traffic Server itself consists of an event-driven loop that can be simplified as follows:
for (;;) {
event = get_next_event();
handle_event (event); }
You compile your plugin source code to create a shared library that Traffic Server loads when it is started. Your plugin contains callback functions that are registered for specific Traffic Server events. When Traffic Server needs to process an event, it invokes any and all call-back functions you've registered for that event type.
Possible uses for plugins include the following:
The Traffic Server API adheres to the following naming conventions:
When Traffic Server is first started, it consults the plugin.config file to determine the names of all shared plugin libraries that need to be loaded. The plugin.config file also defines arguments that are to be passed to each plugin's initialization function, TSPluginInit(). The records.config file defines the path to each plugin shared library.
The sample plugin.config file below contains a comment line, a blank line, and two plugin configurations:
# This is a comment line. my-plugin.so www.junk.com www.trash.com www.garbage.com some-plugin.so arg1 arg2 $proxy.config.http.cache.on
Each plugin configuration in the plugin.config file resembles a UNIX or DOS shell command; each line in plugin.config cannot exceed 1023 characters.
The first plugin configuration is for a plugin named my-plugin.so. It contains three arguments that are to be passed to that plugin's initialization routine. The second configuration is for a plugin named some-plugin.so; it contains three arguments. The last argument, $proxy.config.http.cache.on, is actually a configuration variable. Traffic Server will look up the specified configuration variable and substitute its value.
Plugins are loaded and initialized by Traffic Server in the order they appear in the plugin.config file.
Each plugin must define an initialization function named TSPluginInit() that Traffic Server invokes when the plugin is loaded. TSPluginInit() is commonly used to read configuration information and register hooks for event notification.
plugin.config, records.config
2023, dev@trafficserver.apache.org
November 2, 2023 | 9.2 |