> On Jul 24, 2016, at 11:08 PM, Oliver Goodman <o...@optusnet.com.au> wrote:
> 
> JIRA issue TS-4698 and pull request 
> https://github.com/apache/trafficserver/pull/822 propose to add a TS API 
> function to determine whether the current client request represents a 
> websocket connection attempt.
> 
> The motivation: I’ve been working on a C++ API intercept plugin which, among 
> other things, is able to terminate websocket connections. I thought it might 
> be of interest to contribute a websocket termination example (see TS-4699 and 
> the associated pull request https://github.com/apache/trafficserver/pull/824).
> 
> In order for such a plugin to determine whether the incoming connection is a 
> websocket connection it seems appropriate that
> * it use the same test that TS already uses internally to make this decision, 
> and that
> * the ‘official correct way’ to make this decision be exposed through an API 
> function.
> 
> For this purpose I’m proposing to add a function called TSHttpTxnIsWebsocket. 
> It takes a TSHttpTxn and returns a C int, to be interpreted as a bool in the 
> standard C way, namely non-zero means true.

Thanks Oliver. This API looks OK to me, I haven’t reviewed the documentation 
yet, but we should make sure to be clear when in the state machine this API 
will return valid results.

Can we get consensus on whether this should return “int” or “TSReturnCode”?

jpeach$ grep 'TS.*Is.*' proxy/api/ts/ts.h
tsapi int TSVConnIsSsl(TSVConn sslp);
/** @deprecated to be renamed as TSHttpTxnIsInternal **/
tsapi TS_DEPRECATED TSReturnCode TSHttpIsInternalRequest(TSHttpTxn txnp);
/** @deprecated to be renamed as TSHttpSsnIsInternal **/
tsapi TS_DEPRECATED TSReturnCode TSHttpIsInternalSession(TSHttpSsn ssnp);
tsapi TSReturnCode TSHttpTxnIsInternal(TSHttpTxn txnp);
tsapi TSReturnCode TSHttpSsnIsInternal(TSHttpSsn ssnp);
tsapi int TSIsDebugTagSet(const char *t);
tsapi int TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer 
response);

TSHttpSsnIsInternal is the most recent so I think we should prefer TSReturnCode 
for new code?

> 
> The test checks whether the HttpSM state is_upgrade_request flag is set with 
> an upgrade_token_wks of MIME_VALUE_WEBSOCKET. IIUC this is equivalent to the 
> incoming request having an upgrade header with a value of `websocket`.
> 
> Documentation for this very simple function is in TSHttpTxnIsWebsocket.en.rst 
> in the PR.
> 
> Cheers,
> Oliver
> 

Reply via email to