Example Plugins

Header-Based Plugin Examples

Header-based plugins read or modify the headers of HTTP messages that Traffic Server sends and receives. Reading this chapter will help you to understand the following topics:

  • Creating continuations for your plugins

  • Adding global hooks

  • Adding transaction hooks

  • Working with HTTP header functions

The two sample plugins discussed in this chapter are blacklist_1.c and basic_auth.c. To build and install the example plugins use

./configure --enable-example-plugins

when setting the build configuration for Traffic Server.

Overview

Header-based plugins take actions based on the contents of HTTP request or response headers. Examples include filtering (on the basis of requested URL, source IP address, or other request header), user authentication, or user redirection. Header-based plugins have the following common elements:

  • The plugin has a static parent continuation that scans all Traffic Server headers (either request headers, response headers, or both).

  • The plugin has a global hook. This enables the plugin to check all transactions to determine if the plugin needs to do something.

  • The plugin gets a handle to the transaction being processed through the global hook.

  • If the plugin needs to do something to transactions in specific cases, then it sets up a transaction hook for a particular event.

  • The plugin obtains client header information and does something based on that information.

This chapter demonstrates how these components are implemented in SDK sample code.