You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by br...@apache.org on 2015/11/12 06:17:53 UTC

trafficserver git commit: TS-4010: Add cached request/response to the CPP API transaction object

Repository: trafficserver
Updated Branches:
  refs/heads/master 447ad332f -> e5fed4006


TS-4010: Add cached request/response to the CPP API transaction object


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/e5fed400
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/e5fed400
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/e5fed400

Branch: refs/heads/master
Commit: e5fed400699855ecb27e0e17cd0f2380daddcb70
Parents: 447ad33
Author: Boaz Reicher <bo...@yahoo-inc.com>
Authored: Wed Nov 11 21:17:30 2015 -0800
Committer: Brian Geffon <br...@apache.org>
Committed: Wed Nov 11 21:17:30 2015 -0800

----------------------------------------------------------------------
 lib/atscppapi/src/Transaction.cc                | 51 +++++++++++++++++++-
 .../src/include/atscppapi/Transaction.h         | 31 ++++++++++++
 lib/atscppapi/src/include/utils_internal.h      | 12 +++++
 lib/atscppapi/src/utils_internal.cc             |  5 ++
 4 files changed, 98 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e5fed400/lib/atscppapi/src/Transaction.cc
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/Transaction.cc b/lib/atscppapi/src/Transaction.cc
index 7361cbd..30b2806 100644
--- a/lib/atscppapi/src/Transaction.cc
+++ b/lib/atscppapi/src/Transaction.cc
@@ -52,13 +52,20 @@ struct atscppapi::TransactionState : noncopyable {
   TSMBuffer client_response_hdr_buf_;
   TSMLoc client_response_hdr_loc_;
   Response client_response_;
+  TSMBuffer cached_response_hdr_buf_;
+  TSMLoc cached_response_hdr_loc_;
+  Response cached_response_;
+  TSMBuffer cached_request_hdr_buf_;
+  TSMLoc cached_request_hdr_loc_;
+  Request cached_request_;
   map<string, shared_ptr<Transaction::ContextValue> > context_values_;
 
   TransactionState(TSHttpTxn txn, TSMBuffer client_request_hdr_buf, TSMLoc client_request_hdr_loc)
     : txn_(txn), client_request_hdr_buf_(client_request_hdr_buf), client_request_hdr_loc_(client_request_hdr_loc),
       client_request_(txn, client_request_hdr_buf, client_request_hdr_loc), server_request_hdr_buf_(NULL),
       server_request_hdr_loc_(NULL), server_response_hdr_buf_(NULL), server_response_hdr_loc_(NULL), client_response_hdr_buf_(NULL),
-      client_response_hdr_loc_(NULL){};
+      client_response_hdr_loc_(NULL), cached_response_hdr_buf_(NULL), cached_response_hdr_loc_(NULL), cached_request_hdr_buf_(NULL),
+      cached_request_hdr_loc_(NULL){};
 };
 
 Transaction::Transaction(void *raw_txn)
@@ -93,6 +100,14 @@ Transaction::~Transaction()
     LOG_DEBUG("Releasing client response");
     TSHandleMLocRelease(state_->client_response_hdr_buf_, NULL_PARENT_LOC, state_->client_response_hdr_loc_);
   }
+  if (state_->cached_request_hdr_buf_ && state_->cached_request_hdr_loc_) {
+    LOG_DEBUG("Releasing cached request");
+    TSHandleMLocRelease(state_->cached_request_hdr_buf_, NULL_PARENT_LOC, state_->cached_request_hdr_loc_);
+  }
+  if (state_->cached_response_hdr_buf_ && state_->cached_response_hdr_loc_) {
+    LOG_DEBUG("Releasing cached response");
+    TSHandleMLocRelease(state_->cached_response_hdr_buf_, NULL_PARENT_LOC, state_->cached_response_hdr_loc_);
+  }
   delete state_;
 }
 
@@ -238,6 +253,18 @@ Transaction::getClientResponse()
   return state_->client_response_;
 }
 
+Request &
+Transaction::getCachedRequest()
+{
+  return state_->cached_request_;
+}
+
+Response &
+Transaction::getCachedResponse()
+{
+  return state_->cached_response_;
+}
+
 string
 Transaction::getEffectiveUrl()
 {
@@ -450,3 +477,25 @@ Transaction::initClientResponse()
     state_->client_response_.init(state_->client_response_hdr_buf_, state_->client_response_hdr_loc_);
   }
 }
+
+void
+Transaction::initCachedRequest()
+{
+  static initializeHandles initializeCachedRequestHandles(TSHttpTxnCachedReqGet);
+  if (initializeCachedRequestHandles(state_->txn_, state_->cached_request_hdr_buf_, state_->cached_request_hdr_loc_,
+                                     "cached request")) {
+    LOG_DEBUG("Initializing cached request");
+    state_->cached_request_.init(state_->cached_request_hdr_buf_, state_->cached_request_hdr_loc_);
+  }
+}
+
+void
+Transaction::initCachedResponse()
+{
+  static initializeHandles initializeCachedResponseHandles(TSHttpTxnCachedRespGet);
+  if (initializeCachedResponseHandles(state_->txn_, state_->cached_response_hdr_buf_, state_->cached_response_hdr_loc_,
+                                      "cached response")) {
+    LOG_DEBUG("Initializing cached response");
+    state_->cached_response_.init(state_->cached_response_hdr_buf_, state_->cached_response_hdr_loc_);
+  }
+}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e5fed400/lib/atscppapi/src/include/atscppapi/Transaction.h
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/include/atscppapi/Transaction.h b/lib/atscppapi/src/include/atscppapi/Transaction.h
index dcd9cf4..805807b 100644
--- a/lib/atscppapi/src/include/atscppapi/Transaction.h
+++ b/lib/atscppapi/src/include/atscppapi/Transaction.h
@@ -225,6 +225,21 @@ public:
   Response &getClientResponse();
 
   /**
+   * Returns a Request object which is the cached request
+   *
+   * @return Request object
+   */
+  Request &getCachedRequest();
+
+  /**
+   * Returns a Response object which is the cached response
+   *
+   * @return Response object
+   */
+  Response &getCachedResponse();
+
+
+  /**
    * Returns the Effective URL for this transaction taking into account host.
    */
   std::string getEffectiveUrl();
@@ -363,6 +378,22 @@ private:
   void initClientResponse();
 
   /**
+   * Used to initialize the Request object for the cache.
+   *
+   * @private
+   */
+
+  void initCachedRequest();
+
+  /**
+   * Used to initialize the Response object for the cache.
+   *
+   * @private
+   */
+
+  void initCachedResponse();
+
+  /**
    * Returns a list of TransactionPlugin pointers bound to the current Transaction
    *
    * @private

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e5fed400/lib/atscppapi/src/include/utils_internal.h
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/include/utils_internal.h b/lib/atscppapi/src/include/utils_internal.h
index c08636e..e9dc504 100644
--- a/lib/atscppapi/src/include/utils_internal.h
+++ b/lib/atscppapi/src/include/utils_internal.h
@@ -89,6 +89,18 @@ namespace utils
       transaction.initClientResponse();
     }
 
+    static void
+    initTransactionCachedRequest(Transaction &transaction)
+    {
+      transaction.initCachedRequest();
+    }
+
+    static void
+    initTransactionCachedResponse(Transaction &transaction)
+    {
+      transaction.initCachedResponse();
+    }
+
     static const std::list<TransactionPlugin *> &
     getTransactionPlugins(const Transaction &transaction)
     {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e5fed400/lib/atscppapi/src/utils_internal.cc
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/utils_internal.cc b/lib/atscppapi/src/utils_internal.cc
index a62e1b8..ff0012e 100644
--- a/lib/atscppapi/src/utils_internal.cc
+++ b/lib/atscppapi/src/utils_internal.cc
@@ -69,6 +69,10 @@ handleTransactionEvents(TSCont cont, TSEvent event, void *edata)
   case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
     utils::internal::initTransactionClientResponse(transaction);
     break;
+  case TS_EVENT_HTTP_READ_CACHE_HDR:
+    utils::internal::initTransactionCachedRequest(transaction);
+    utils::internal::initTransactionCachedResponse(transaction);
+    break;
   case TS_EVENT_HTTP_TXN_CLOSE: { // opening scope to declare plugins variable below
     const std::list<TransactionPlugin *> &plugins = utils::internal::getTransactionPlugins(transaction);
     for (std::list<TransactionPlugin *>::const_iterator iter = plugins.begin(), end = plugins.end(); iter != end; ++iter) {
@@ -99,6 +103,7 @@ setupTransactionManagement()
   TSHttpHookAdd(TS_HTTP_SEND_REQUEST_HDR_HOOK, cont);
   TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, cont);
   TSHttpHookAdd(TS_HTTP_SEND_RESPONSE_HDR_HOOK, cont);
+  TSHttpHookAdd(TS_HTTP_READ_CACHE_HDR_HOOK, cont);
   TSHttpHookAdd(TS_HTTP_TXN_CLOSE_HOOK, cont);
 }