trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject [1/2] git commit: TS-1622 Add an API to query if a response header would be cacheable
Date Mon, 10 Feb 2014 14:03:56 GMT
Updated Branches:
  refs/heads/master 3b1677607 -> 069c79ecf


TS-1622 Add an API to query if a response header would be cacheable


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

Branch: refs/heads/master
Commit: 77a0583913153849d4d2e7baf5de03ef396ca2da
Parents: 3b16776
Author: Leif Hedstrom <zwoop@apache.org>
Authored: Thu Feb 6 20:18:45 2014 -0700
Committer: Leif Hedstrom <zwoop@apache.org>
Committed: Mon Feb 10 07:00:28 2014 -0700

----------------------------------------------------------------------
 proxy/InkAPI.cc      | 26 ++++++++++++++++++++++++++
 proxy/api/ts/ts.h.in | 14 +++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/77a05839/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 01d1836..7067819 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -8291,3 +8291,29 @@ TSHttpTxnBackgroundFillStarted(TSHttpTxn txnp)
 
   return (s->background_fill == BACKGROUND_FILL_STARTED);
 }
+
+int
+TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response)
+ {
+   sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
+   HttpSM *sm = (HttpSM *) txnp;
+   HTTPHdr *req, *resp;
+
+   // We allow for either request or response to be empty (or both), in
+   // which case we default to the transactions request or response.
+   if (request) {
+     sdk_sanity_check_mbuffer(request);
+     req = reinterpret_cast<HTTPHdr*>(request);
+   } else {
+     req = &(sm->t_state.hdr_info.client_request);
+   }
+   if (response) {
+     sdk_sanity_check_mbuffer(response);
+     resp = reinterpret_cast<HTTPHdr*>(response);
+   } else {
+     resp = &(sm->t_state.hdr_info.server_response);
+   }
+
+   // Make sure these are valid response / requests, then verify if it's cacheable.
+   return (req->valid() && resp->valid() && HttpTransact::is_response_cacheable(&(sm->t_state),
req, resp)) ? 1: 0;
+ }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/77a05839/proxy/api/ts/ts.h.in
----------------------------------------------------------------------
diff --git a/proxy/api/ts/ts.h.in b/proxy/api/ts/ts.h.in
index ee4a720..b37a504 100644
--- a/proxy/api/ts/ts.h.in
+++ b/proxy/api/ts/ts.h.in
@@ -3299,10 +3299,22 @@ extern "C"
   */
   tsapi TSReturnCode TSHttpTxnMilestoneGet(TSHttpTxn txnp, TSMilestonesType milestone, TSHRTime
*time);
 
+  /**
+    Test whether a request / response header pair would be cacheable under the current
+    configuration. This would typically be used in TS_HTTP_READ_RESPONSE_HDR_HOOK, when
+    you have both the client request and server response ready.
+
+    @param txnp the transaction pointer
+    @param request the client request header. If NULL, use the transactions client request.
+    @param response the server response header. If NULL, use the transactions origin response.
+
+    @return 1 if the request / response is cacheable, 0 otherwise
+  */
+  tsapi int TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response);
+
 
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
 
 #endif /* __TS_API_H__ */
-


Mime
View raw message