trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject [trafficserver] branch master updated: TS-4698: Adds an API call to identify WebSocket requests.
Date Fri, 23 Sep 2016 22:23:12 GMT
This is an automated email from the ASF dual-hosted git repository.

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  9228329   TS-4698: Adds an API call to identify WebSocket requests.
9228329 is described below

commit 92283299b7c65df595f3cedb4f6bfd3360711838
Author: Oliver Goodman <oag@optusnet.com.au>
AuthorDate: Sat Aug 20 10:16:41 2016 +0000

    TS-4698: Adds an API call to identify WebSocket requests.
    
    Add the TSHttpTxnIsWebsocket API to make it possible for plugins
    to detect incoming WebSocket connections and thereby provide WebSocket
    termination if desired.
    
    This closes #822.
---
 .../api/functions/TSHttpTxnIsWebsocket.en.rst      | 45 ++++++++++++++++++++++
 lib/atscppapi/src/InterceptPlugin.cc               |  5 +++
 lib/atscppapi/src/TransactionPlugin.cc             |  6 +++
 .../src/include/atscppapi/TransactionPlugin.h      |  2 +
 proxy/InkAPI.cc                                    |  9 +++++
 proxy/api/ts/ts.h                                  |  1 +
 6 files changed, 68 insertions(+)

diff --git a/doc/developer-guide/api/functions/TSHttpTxnIsWebsocket.en.rst b/doc/developer-guide/api/functions/TSHttpTxnIsWebsocket.en.rst
new file mode 100644
index 0000000..c60dc9d
--- /dev/null
+++ b/doc/developer-guide/api/functions/TSHttpTxnIsWebsocket.en.rst
@@ -0,0 +1,45 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+.. default-domain:: c
+
+TSHttpTxnIsWebsocket
+********************
+
+Test whether a request is attempting to initiate Websocket connection.
+
+Synopsis
+========
+
+`#include <ts/ts.h>`
+
+.. function:: int TSHttpTxnIsWebsocket(TSHttpTxn txnp)
+
+Description
+===========
+
+:func:`TSHttpTxnIsWebsocket` tests whether the transaction
+is a WebSocket upgrade request.
+
+Return Values
+=============
+
+A non-zero value is returned if the relevant header value is found.
+
+See also
+========
+
+:manpage:`TSAPI(3ts)`
diff --git a/lib/atscppapi/src/InterceptPlugin.cc b/lib/atscppapi/src/InterceptPlugin.cc
index b1e9dc7..8609585 100644
--- a/lib/atscppapi/src/InterceptPlugin.cc
+++ b/lib/atscppapi/src/InterceptPlugin.cc
@@ -254,6 +254,11 @@ InterceptPlugin::doRead()
   // Modify the input VIO to reflect how much data we've completed.
   TSVIONDoneSet(state_->input_.vio_, TSVIONDoneGet(state_->input_.vio_) + consumed);
 
+  if (isWebsocket()) {
+    TSVIOReenable(state_->input_.vio_);
+    return true;
+  }
+
   if ((state_->hdr_parsed_) && (state_->num_body_bytes_read_ >= state_->expected_body_size_))
{
     LOG_DEBUG("Completely read body");
     if (state_->num_body_bytes_read_ > state_->expected_body_size_) {
diff --git a/lib/atscppapi/src/TransactionPlugin.cc b/lib/atscppapi/src/TransactionPlugin.cc
index bac2a75..67f0c5f 100644
--- a/lib/atscppapi/src/TransactionPlugin.cc
+++ b/lib/atscppapi/src/TransactionPlugin.cc
@@ -72,6 +72,12 @@ TransactionPlugin::getMutex()
   return state_->mutex_;
 }
 
+bool
+TransactionPlugin::isWebsocket() const
+{
+  return TSHttpTxnIsWebsocket(state_->ats_txn_handle_);
+}
+
 TransactionPlugin::~TransactionPlugin()
 {
   LOG_DEBUG("Destroying TransactionPlugin=%p", this);
diff --git a/lib/atscppapi/src/include/atscppapi/TransactionPlugin.h b/lib/atscppapi/src/include/atscppapi/TransactionPlugin.h
index 7295d4b..8455938 100644
--- a/lib/atscppapi/src/include/atscppapi/TransactionPlugin.h
+++ b/lib/atscppapi/src/include/atscppapi/TransactionPlugin.h
@@ -94,6 +94,8 @@ public:
   void registerHook(Plugin::HookType hook_type);
   virtual ~TransactionPlugin();
 
+  bool isWebsocket() const;
+
 protected:
   TransactionPlugin(Transaction &transaction);
 
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 30e5fc7..cc00c87 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -4994,6 +4994,15 @@ TSHttpTxnInfoIntGet(TSHttpTxn txnp, TSHttpTxnInfoKey key, TSMgmtInt
*value)
   return TS_SUCCESS;
 }
 
+int
+TSHttpTxnIsWebsocket(TSHttpTxn txnp)
+{
+  sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
+
+  HttpSM *sm = (HttpSM *)txnp;
+  return sm->t_state.is_websocket;
+}
+
 TSReturnCode
 TSHttpTxnCacheLookupUrlGet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj)
 {
diff --git a/proxy/api/ts/ts.h b/proxy/api/ts/ts.h
index 6dfcf53..d013b67 100644
--- a/proxy/api/ts/ts.h
+++ b/proxy/api/ts/ts.h
@@ -2334,6 +2334,7 @@ tsapi TSReturnCode TSHttpTxnCacheLookupUrlGet(TSHttpTxn txnp, TSMBuffer
bufp, TS
 tsapi TSReturnCode TSHttpTxnCacheLookupUrlSet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj);
 tsapi TSReturnCode TSHttpTxnPrivateSessionSet(TSHttpTxn txnp, int private_session);
 tsapi int TSHttpTxnBackgroundFillStarted(TSHttpTxn txnp);
+tsapi int TSHttpTxnIsWebsocket(TSHttpTxn txnp);
 
 /* Get the Txn's (HttpSM's) unique identifier, which is a sequence number since server start)
*/
 tsapi uint64_t TSHttpTxnIdGet(TSHttpTxn txnp);

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Mime
View raw message