博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

官网 hooks

Posted on 2017-08-31 16:52  bw_0927  阅读(511)  评论(0)    收藏  举报

https://docs.trafficserver.apache.org/en/6.2.x/developer-guide/plugins/hooks-and-transactions/adding-hooks.en.html

 

 

Adding Hooks

There are several ways to add hooks to your plugin.

  • Global HTTP hooks

HTTP transaction hooks are set on a global basis using the function TSHttpHookAdd. This means that the continuation specified as the parameter to TSHttpHookAdd is called for every transactionTSHttpHookAdd must be used in TSPluginInit.

通过TSHttpHookAdd添加的全局hook,每个transction都会回到TSHttpHookAdd的continuation参数

  • Transaction hooks

Transaction hooks can be used to call plugins back for a specific HTTP transaction. You cannot add transaction hooks in TSPluginInit; you first need a handle to a transaction. See Accessing the Transaction Being Processed.

某个特定transaction的hook

  • Transformation hooks

Transformation hooks are a special case of transaction hooks. SeeTSVConnCacheObjectSizeGet() for more information about transformation hooks. You add a transformation hook using TSHttpTxnHookAdd, as described in HTTP Transactions.

通过TSHttpTxnHookAdd添加的transformation hook,transformation hook是transction hook的一种特例

  • Session hooks

 An HTTP session starts when a client opens a connection to Traffic Server and ends when the connection closes. A session can consist of several transactions. Session hooks enable you to hook your plugin to a particular point in every transaction within a specified session (see HTTP Sessions). , TSHttpSsnHookAdd() Session hooks are added in a manner similar to transaction hooks (ie, you first need a handle to an HTTP session).

  • HTTP select alternate hook Alternate selection hooks enable you to hook on to the alternate selection state. These hooks must be added globally, since Traffic Server does not have a handle to a transaction or session when alternate selection is taking place. See HTTP Alternate Selection for information on the alternate selection mechanism.

All of the hook addition functions (TSHttpHookAdd()TSHttpSsnHookAdd()TSHttpSsnReenable()) take TSHttpHookID (identifies the hook to add on to) and TSCont (the basic callback mechanism in Traffic Server). A single TSCont can be added to any number of hooks at a time.

An HTTP hook is identified by the enumerated type TSHttpHookID

 

http://www.cnblogs.com/my_life/articles/7458108.html

添加的是全局的hook还是局部的hook,不是已hook_id来区分的,而是以用来添加hook的api来区分的

TSHttpHookAdd: 添加全局的hook, 此api必须在TSPluginInit中调用

TSHttpTxnHookAdd:添加局部的hook,hook特定的transaction

TShttpSsnHookAdd:添加session hook,hook特定的session中的所有的transaction。

 

 

============================================

https://docs.trafficserver.apache.org/en/6.2.x/developer-guide/api/functions/TSHttpHookAdd.en.html#c.TSHttpTxnHookAdd

void TSHttpHookAdd(TSHttpHookID idTSCont contp)                      //全局hook,在TSPluginInit或TSRemapInit中调用
void TSHttpSsnHookAdd(TSHttpSsn ssnpTSHttpHookID idTSCont contp)          //session hook,所以需要一个指向特定session的指针,即第一个参数TSHttpSsn ssnp,contp会被该session内的所有transaction回调。
void TSHttpTxnHookAdd(TSHttpTxn txnpTSHttpHookID idTSCont contp)          //transaction hook, 所以需要一个指向特定transaction的指针,即第一个参数TSHttpTxn txnp

 

HTTP transaction hooks are set on a global basis using the function TSHttpHookAdd(). This means that the continuation specified as the parameter to TSHttpHookAdd() is called for every transaction. TSHttpHookAdd() is typically called from TSPluginInit() or TSRemapInit().

通过TSHttpHookAdd()添加全局的hook。这意味着TSHttpHookAdd()的continuation参数将会被每一个transaction回调。 TSHttpHookAdd函数通常在TSPluginInit()或者TSRemapInit()中被调用。

TSHttpSsnHookAdd() adds contp to the end of the list of HTTP session hooks specified by id. This means that contp is called back for every transaction within the session, at the point specified by the hook ID. Since contp is added to a session, it is not possible to call TSHttpSsnHookAdd() from the plugin initialization routine; the plugin needs a handle to an HTTP session.

TSHttpSsnHookAdd()用来给某个特定session添加hook,所以它需要一个指向特定session的handler。因此该特定session内的的所有transaction都会回调contp。 TSHttpSsnHookAdd()不应该在插件初始化的函数里调用

TSHttpTxnHookAdd() adds contp to the end of the list of HTTP transaction hooks specified by id. Since contp is added to a transaction, it is not possible to call TSHttpTxnHookAdd() from the plugin initialization routine but only when the plugin has a handle to an HTTP transaction.

TSHttpTxnHookAdd是添加某个局部的transaction的hook,因此它不能在插件初始化的函数里调用,只有在获得了某个transaction的指针的时候才可以调用。