You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by Maurice Kelly <ma...@openwave.com> on 2012/02/10 10:27:41 UTC
Plugin API: retrieving connection details in HTTP session hook
Hi,
I have a need to determine the connection details of the client and TS as part of the HTTP session hook. This will allow further plugin activity to be determined based on a decision making process at the start of the session rather than for each individual HTTP transaction.
I can see that with a TSHttpTxn I can utilise API calls such as TSHttpTxnClientAddrGet and TSHttpTxnIncomingAddrGet in order to retrieve the information, but I see no equivalents for use with a TSHttpSsn (I would have expected to see equivalents such as TSHttpSsnClientAddrGet/TSHttpSsnIncomingAddrGet.
Is there a way for me to get this information for the HTTP session through the plugin API as it would seem logical that the connection information would be known at this point in time.
Cheers,
Maurice
Re: Plugin API: retrieving connection details in HTTP session hook
Posted by Maurice Kelly <ma...@openwave.com>.
On 10 Feb 2012, at 12:14, Maurice Kelly wrote:
> On 10 Feb 2012, at 11:41, Nick Kew wrote:
>
>> It would be great if you could ignore my comments and just try it for yourself.
>> A second independent opinion might tell us something worthwhile about
>> just how useful the API really is as of now.
>
>
> No problem - will download the 3.1.2 release and give it a go with that.
Only managed to do a quick test but I seem to be able to get the IP address from the SSN_START hook.
Below you'll see the plugin function I'm using. I've added it as with the following hook:
TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, TSContCreate(start_hook, NULL));
and the start_hook function:
static int
start_hook(TSCont contp, TSEvent event, void *edata) {
TSDebug(DEBUG_ID, "Entering start_hook()");
TSHttpSsn ssnp;
TSHttpTxn txnp;
const struct sockaddr* sa;
const struct sockaddr_in* si;
switch (event) {
case TS_EVENT_HTTP_SSN_START:
ssnp = (TSHttpSsn)edata;
sa = TSHttpSsnClientAddrGet(ssnp);
si = (const struct sockaddr_in*)sa;
TSDebug(DEBUG_ID, "Address from SSN START: %s", inet_ntoa(si->sin_addr));
TSHttpSsnHookAdd(ssnp, TS_HTTP_TXN_START_HOOK, contp);
TSHttpSsnReenable(ssnp, TS_EVENT_HTTP_CONTINUE);
break;
case TS_EVENT_HTTP_TXN_START:
txnp = (TSHttpTxn)edata;
sa = TSHttpTxnClientAddrGet(txnp);
si = (const struct sockaddr_in*)sa;
TSDebug(DEBUG_ID, "Address from TXN_START: %s", inet_ntoa(si->sin_addr));
TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
default:
break;
}
return 0;
}
The output reads:
[Feb 10 16:24:27.266] Server {0x7fc34756e700} DIAG: (testssn) Entering start_hook()
[Feb 10 16:24:27.266] Server {0x7fc34756e700} DIAG: (testssn) Address from SSN START: 192.168.91.1
[Feb 10 16:24:27.266] Server {0x7fc34756e700} DIAG: (testssn) Entering start_hook()
[Feb 10 16:24:27.266] Server {0x7fc34756e700} DIAG: (testssn) Address from TXN_START: 192.168.91.1
Is this what you would have expected?
Cheers,
Maurice
Re: Plugin API: retrieving connection details in HTTP session hook
Posted by Maurice Kelly <ma...@openwave.com>.
On 10 Feb 2012, at 11:41, Nick Kew wrote:
> It would be great if you could ignore my comments and just try it for yourself.
> A second independent opinion might tell us something worthwhile about
> just how useful the API really is as of now.
No problem - will download the 3.1.2 release and give it a go with that.
Thanks for the feedback.
Cheers,
Maurice
Re: Plugin API: retrieving connection details in HTTP session hook
Posted by Nick Kew <ni...@apache.org>.
On 10 Feb 2012, at 11:08, Maurice Kelly wrote:
> Your comment in the JIRA issue says: "This doesn't fix the underlying problem, as the connection data are unavailable in a SSN Init hook!" Does this mean that at this point the HTTPClientSession is not fully populated in order to get access to the NetVC?
>
> Can I assume then that it's not until the first TXN hook is encountered that the HTTPClientSession object actually gets fully populated?
It would be great if you could ignore my comments and just try it for yourself.
A second independent opinion might tell us something worthwhile about
just how useful the API really is as of now.
--
Nick Kew
Re: Plugin API: retrieving connection details in HTTP session hook
Posted by Maurice Kelly <ma...@openwave.com>.
On 10 Feb 2012, at 09:52, Nick Kew wrote:
> On 10 Feb 2012, at 09:27, Maurice Kelly wrote:
>
>> Is there a way for me to get this information for the HTTP session through the plugin API as it would seem logical that the connection information would be known at this point in time.
>
> Yes and no.
>
> https://issues.apache.org/jira/browse/TS-1008
The code changes seem to be there (the yes, I presume) so what is the problem that makes you say no?
Your comment in the JIRA issue says: "This doesn't fix the underlying problem, as the connection data are unavailable in a SSN Init hook!" Does this mean that at this point the HTTPClientSession is not fully populated in order to get access to the NetVC?
Can I assume then that it's not until the first TXN hook is encountered that the HTTPClientSession object actually gets fully populated?
Cheers,
Maurice
Re: Plugin API: retrieving connection details in HTTP session hook
Posted by Nick Kew <ni...@apache.org>.
On 10 Feb 2012, at 09:27, Maurice Kelly wrote:
> Is there a way for me to get this information for the HTTP session through the plugin API as it would seem logical that the connection information would be known at this point in time.
Yes and no.
https://issues.apache.org/jira/browse/TS-1008
--
Nick Kew