Home

Traffic Server Software Developers Kit

Adding Hooks

There are several ways to add hooks to your plugin.

All of the hook addition functions (INKHttpHookAdd, INKHttpSsnHookAdd, INKHttpSsnReenable) take INKHttpHookID (identifies the hook to add on to) and INKCont (the basic callback mechanism in Traffic Server). A single INKCont can be added to any number of hooks at a time.

An HTTP hook is identified by the enumerated type INKHttpHookID. The values for INKHttpHookID are:

Table 8.1. INKHttpHookID Values
Values for INKHttpHookID Description
INK_HTTP_READ_REQUEST_HDR_HOOK Called immediately after the request header is read from the client. Corresponds to the event INK_EVENT_HTTP_READ_REQUEST_HDR.
INK_HTTP_OS_DNS_HOOK Called immediately after the HTTP state machine has completed a DNS lookup of the origin server. The HTTP state machine will know the origin server's IP address at this point, which is useful for performing both authentication and blacklisting. Corresponds to the event INK_EVENT_HTTP_OS_DNS.
INK_HTTP_SEND_REQUEST_HDR_HOOK Called immediately before the proxy's request header is sent to the origin server or the parent proxy. This hook is not called if the document is being served from cache. This hook is usually used for modifying the proxy's request header before it is sent to the origin server or parent proxy.
INK_HTTP_READ_CACHE_HDR_HOOK Called immediately after the request and response header of a previously-cached object is read from cache. This hook is only called if the document is being served from cache. Corresponds to the event INK_EVENT_HTTP_READ_CACHE_HDR.
INK_HTTP_READ_RESPONSE_HDR_HOOK Called immediately after the response header is read from the origin server or parent proxy. Corresponds to the event INK_EVENT_HTTP_READ_RESPONSE_HDR.
INK_HTTP_SEND_RESPONSE_HDR_HOOK Called immediately before the proxy's response header is written to the client; this hook is usually used for modifying the response header. Corresponds to the event INK_EVENT_HTTP_SEND_RESPONSE_HDR.
INK_HTTP_REQUEST_TRANSFORM_HOOK See“Transformations” for information about transformation hooks.
INK_HTTP_RESPONSE_TRANSFORM_HOOK See ““Transformations” for information about transformation hooks.
INK_HTTP_TXN_START_HOOK Called when an HTTP transaction is started. A transaction starts when either a client connects to Traffic Server and data is available on the connection, or a previous client connection that was left open for keep alive has new data available.
INK_HTTP_TXN_CLOSE_HOOK Called when an HTTP transaction ends.
INK_HTTP_SELECT_ALT_HOOK See “HTTP Alternate Selection” for information about the alternate selection mechanism.
INK_HTTP_SSN_START_HOOK Called when an HTTP session is started. A session starts when a client connects to Traffic Server. You can only add this hook as a global hook.
INK_HTTP_SSN_CLOSE_HOOK Called when an HTTP session ends. A session ends when the client connection is closed. You can only add this hook as a global hook
INK_HTTP_CACHE_LOOKUP_COMPLETE_HOOK Called after the HTTP state machine has commpleted the cache lookup for the document requested in the ongoing transaction. Register this hook via INKHttpTxnHookAdd or INKHttpHookAdd. Corresponds to the event INK_EVENT_HTTP_CACHE_LOOKUP_COMPLETE.

The function you use to add a global HTTP hook is INKHttpHookAdd.