.\" Man page generated from reStructuredText. . .TH "TSHTTPHOOKADD" "3ts" "Jan 04, 2023" "8.1" "Apache Traffic Server" .SH NAME TSHttpHookAdd \- intercept Traffic Server events . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .SH SYNOPSIS .sp \fI#include \fP .INDENT 0.0 .TP .B void TSHttpHookAdd(TSHttpHookID \fIid\fP, TSCont \fIcontp\fP) .UNINDENT .INDENT 0.0 .TP .B void TSHttpSsnHookAdd(TSHttpSsn \fIssnp\fP, TSHttpHookID \fIid\fP, TSCont \fIcontp\fP) .UNINDENT .INDENT 0.0 .TP .B void TSHttpTxnHookAdd(TSHttpTxn \fItxnp\fP, TSHttpHookID \fIid\fP, TSCont \fIcontp\fP) .UNINDENT .SH DESCRIPTION .sp Hooks are points in Apache Traffic Server transaction HTTP processing where plugins can step in and do some work. Registering a plugin function for callback amounts to adding the function to a hook. You can register your plugin to be called back for every single transaction, or for specific transactions only. .sp HTTP transaction hooks are set on a global basis using the function \fI\%TSHttpHookAdd()\fP\&. This means that the continuation specified as the parameter to \fI\%TSHttpHookAdd()\fP is called for every transaction. \fI\%TSHttpHookAdd()\fP is typically called from \fBTSPluginInit()\fP or \fBTSRemapInit()\fP\&. .sp \fI\%TSHttpSsnHookAdd()\fP adds \fIcontp\fP to the end of the list of HTTP session hooks specified by \fIid\fP\&. This means that \fIcontp\fP is called back for every transaction within the session, at the point specified by the hook ID. Since \fIcontp\fP is added to a session, it is not possible to call \fI\%TSHttpSsnHookAdd()\fP from the plugin initialization routine; the plugin needs a handle to an HTTP session. .sp \fI\%TSHttpTxnHookAdd()\fP adds \fIcontp\fP to the end of the list of HTTP transaction hooks specified by \fIid\fP\&. Since \fIcontp\fP is added to a transaction, it is not possible to call \fI\%TSHttpTxnHookAdd()\fP from the plugin initialization routine but only when the plugin has a handle to an HTTP transaction. .sp A single continuation can be attached to multiple hooks at the same time. It is good practice to conserve resources by reusing hooks in this way when possible. .sp When a continuation on a hook is triggered, the name of the event passed to the continution function depends on the name of the hook. The naming convention is that, for hook TS_xxx_HOOK, the event passed to the continuation function will be TS_EVENT_xxx. For example, when a continuation attached to TS_HTTP_READ_REQUEST_HDR_HOOK is triggered, the event passed to the continuation function will be TS_EVENT_HTTP_READ_REQUEST_HDR. .sp When a continuation is triggered by a hook, the actual type of the event data (the void pointer passed as the third parameter to the continuation function) is determined by which hook it is. For example, for the hook ID TS_HTTP_TXN_CLOSE_HOOK, the event data is of type TSHttpTxn. This is the case regardless of whether the continuation was added to the hook using \fI\%TSHttpTxnHookAdd()\fP, \fI\%TSHttpSsnHookAdd()\fP or \fI\%TSHttpHookAdd()\fP\&. .SH RETURN VALUES .sp None. Adding hooks is always successful. .SH EXAMPLES .sp The following example demonstrates how to add global, session and transaction hooks: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C #include static int handler(TSCont contp, TSEvent event, void *edata) { TSHttpSsn ssnp; TSHttpTxn txnp; switch (event){ case TS_EVENT_HTTP_SSN_START: ssnp = (TSHttpSsn) edata; // Add a session hook ... TSHttpSsnHookAdd(ssnp, TS_HTTP_TXN_START_HOOK, contp); TSHttpSsnReenable(ssnp, TS_EVENT_HTTP_CONTINUE); return 0; case TS_EVENT_HTTP_TXN_START: txnp = (TSHttpTxn) edata; // Add a transaction hook ... TSHttpTxnHookAdd(txnp, TS_HTTP_READ_REQUEST_HDR_HOOK, contp); TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); return 0; default: break; } return 0; } void TSPluginInit (int argc, const char *argv[]) { TSCont contp; contp = TSContCreate(handler, NULL); TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, contp); } .ft P .fi .UNINDENT .UNINDENT .SH SEE ALSO .sp \fBTSAPI(3ts)\fP, \fBTSContCreate(3ts)\fP, \fBTSLifecycleHookAdd(3ts)\fP .SH COPYRIGHT 2023, dev@trafficserver.apache.org .\" Generated by docutils manpage writer. .