Home

Traffic Server Software Developers Kit

Session Functions

INKHttpSsnHookAdd

Adds an HTTP session hook.

Prototype

INKReturnCode INKHttpSsnHookAdd (INKHttpSsn ssnp, INKHttpHookID id, INKCont contp)

Description

Adds contp to the end of the list of HTTP transaction 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 INKHttpSsnHookAdd from the plugin initialization routine. Therefore, the plugin needs a handle to an HTTP session (see the example below).

Example
#include InkAPI.h

static void txn_handler (INKHttpTxn txnp, INKCont contp)
{
     //handle transaction
}

static void handle_session (INKHttpSsn ssnp, INKCont contp)
{
     INKHttpSsnHookAdd (ssnp, INK_HTTP_TXN_START_HOOK, contp);
}

static int ssn_handler (INKCont contp, INKEvent event, void *edata)
{
    INKHttpSsn ssnp;
    INKHttpTxn txnp;

    switch (event){
    case INK_EVENT_HTTP_SSN_START: 
       ssnp = (INKHttpSsn) edata;
       handle_session (ssnp, contp);
       INKHttpSsnReenable (ssnp, INK_EVENT_HTTP_CONTINUE); 
       return 0;

    case INK_EVENT_HTTP_TXN_START:
       txnp = (INKHttpTxn) edata;
       txn_handler (txnp, contp);
       INKHttpTxnReenable (txnp, INK_EVENT_HTTP_CONTINUE);
       return 0;
 
    default:
         break;	
    }
    return 0;
}

void INKPluginInit (int argc, const char *argv[])
{
    INKCont contp;
    contp = INKContCreate (ssn_handler, NULL);
    INKHttpHookAdd (INK_HTTP_SSN_START_HOOK, contp);
}
 
Returns

INK_SUCCESS if the hook is successfully added.

INK_ERROR if the hook is not added.

INKHttpSsnReenable

Reenables an HTTP session.

Prototype

INKReturnCode INKHttpSsnReenable (INKHttpSsn ssnp, INKEvent event)

Description

Notifies the HTTP session ssnp that the plugin is done processing the current hook. If INK_EVENT_HTTP_CONTINUE is specified for event, then the plugin wants the session to continue. If INK_EVENT_HTTP_ERROR is specified for event, then the plugin wants the session to be terminated. An error is then sent back to the client if no response has already been sent.

Returns

INK_SUCCESS if the session is successfully reenabled.

INK_ERROR if the hook is not added.