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 denylist_1.cc and basic_auth.cc. To make this two plugins available, you must enable experimental plugins when building Traffic Server by passing the -DENABLE_EXAMPLE=ON to the cmake command when building.

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.