You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2014/08/09 01:00:23 UTC

git commit: TS-2357: Add option to cache POST requests

Repository: trafficserver
Updated Branches:
  refs/heads/master 7fa5c5c7a -> 2158d61dc


TS-2357: Add option to cache POST requests


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

Branch: refs/heads/master
Commit: 2158d61dc83d88c04204201d55d61005955c1bbd
Parents: 7fa5c5c
Author: Bryan Call <bc...@apache.org>
Authored: Fri Aug 8 16:00:02 2014 -0700
Committer: Bryan Call <bc...@apache.org>
Committed: Fri Aug 8 16:00:02 2014 -0700

----------------------------------------------------------------------
 CHANGES                           |  2 ++
 mgmt/RecordsConfig.cc             |  2 ++
 proxy/http/HttpConfig.cc          |  2 ++
 proxy/http/HttpConfig.h           |  2 ++
 proxy/http/HttpTransact.cc        | 13 +++++++------
 proxy/http/HttpTransactHeaders.cc |  5 +++--
 proxy/http/HttpTransactHeaders.h  |  2 +-
 7 files changed, 19 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2158d61d/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index a6db8d9..f3c0696 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.1.0
 
+  *) [TS-2357] Add option to cache POST requests
+
   *) [TS-2996] Add consistent hash method to parent selection.
 
   *) [TS-2332] Add Consistent Hash class.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2158d61d/mgmt/RecordsConfig.cc
----------------------------------------------------------------------
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index 31890d3..3e96b6b 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -626,6 +626,8 @@ RecordElement RecordsConfig[] = {
   ,
   {RECT_CONFIG, "proxy.config.http.cache.enable_default_vary_headers", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
   ,
+  {RECT_CONFIG, "proxy.config.http.cache.post_method", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
+  ,
   {RECT_CONFIG, "proxy.config.http.cache.max_open_read_retries", RECD_INT, "-1", RECU_NULL, RR_NULL, RECC_NULL, NULL, RECA_NULL}
   ,
   {RECT_CONFIG, "proxy.config.http.cache.open_read_retry_time", RECD_INT, "10", RECU_NULL, RR_NULL, RECC_NULL, NULL, RECA_NULL}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2158d61d/proxy/http/HttpConfig.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.cc b/proxy/http/HttpConfig.cc
index beac3cf..88433a9 100644
--- a/proxy/http/HttpConfig.cc
+++ b/proxy/http/HttpConfig.cc
@@ -1391,6 +1391,7 @@ HttpConfig::startup()
   HttpEstablishStaticConfigByte(c.oride.cache_ignore_auth, "proxy.config.http.cache.ignore_authentication");
   HttpEstablishStaticConfigByte(c.oride.cache_urls_that_look_dynamic, "proxy.config.http.cache.cache_urls_that_look_dynamic");
   HttpEstablishStaticConfigByte(c.cache_enable_default_vary_headers, "proxy.config.http.cache.enable_default_vary_headers");
+  HttpEstablishStaticConfigByte(c.cache_post_method, "proxy.config.http.cache.post_method");
 
   HttpEstablishStaticConfigByte(c.ignore_accept_mismatch, "proxy.config.http.cache.ignore_accept_mismatch");
   HttpEstablishStaticConfigByte(c.ignore_accept_language_mismatch, "proxy.config.http.cache.ignore_accept_language_mismatch");
@@ -1643,6 +1644,7 @@ HttpConfig::reconfigure()
   params->oride.cache_ignore_auth = INT_TO_BOOL(m_master.oride.cache_ignore_auth);
   params->oride.cache_urls_that_look_dynamic = INT_TO_BOOL(m_master.oride.cache_urls_that_look_dynamic);
   params->cache_enable_default_vary_headers = INT_TO_BOOL(m_master.cache_enable_default_vary_headers);
+  params->cache_post_method = INT_TO_BOOL(m_master.cache_post_method);
 
   params->ignore_accept_mismatch = m_master.ignore_accept_mismatch;
   params->ignore_accept_language_mismatch = m_master.ignore_accept_language_mismatch;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2158d61d/proxy/http/HttpConfig.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.h b/proxy/http/HttpConfig.h
index df819db..ae670f7 100644
--- a/proxy/http/HttpConfig.h
+++ b/proxy/http/HttpConfig.h
@@ -707,6 +707,7 @@ public:
   // cache control //
   ///////////////////
   MgmtByte cache_enable_default_vary_headers;
+  MgmtByte cache_post_method;
 
   ////////////////////////////////////////////
   // CONNECT ports (used to be == ssl_ports //
@@ -910,6 +911,7 @@ HttpConfigParams::HttpConfigParams()
     cache_vary_default_other(NULL),
     max_cache_open_write_retries(1),
     cache_enable_default_vary_headers(0),
+    cache_post_method(0),
     connect_ports_string(NULL),
     connect_ports(NULL),
     push_method_enabled(0),

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2158d61d/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 53b8e71..a734b92 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -454,11 +454,12 @@ do_cookies_prevent_caching(int cookies_conf, HTTPHdr* request, HTTPHdr* response
 
 
 inline static bool
-does_method_require_cache_copy_deletion(int method)
+does_method_require_cache_copy_deletion(const HttpConfigParams *http_config_param, const int method)
 {
   return ((method != HTTP_WKSIDX_GET) &&
           (method == HTTP_WKSIDX_DELETE || method == HTTP_WKSIDX_PURGE ||
-           method == HTTP_WKSIDX_PUT || method == HTTP_WKSIDX_POST));
+           method == HTTP_WKSIDX_PUT ||
+           (http_config_param->cache_post_method != 1 && method == HTTP_WKSIDX_POST)));
 }
 
 
@@ -2265,7 +2266,7 @@ HttpTransact::issue_revalidate(State* s)
     // request to the server. is_cache_response_returnable will ensure
     // that we forward the request. We now specify what the cache
     // action should be when the response is received.
-    if (does_method_require_cache_copy_deletion(s->method)) {
+    if (does_method_require_cache_copy_deletion(s->http_config_param, s->method)) {
       s->cache_info.action = CACHE_PREPARE_TO_DELETE;
       DebugTxn("http_seq", "[HttpTransact::issue_revalidate] cache action: DELETE");
     } else {
@@ -3038,7 +3039,7 @@ HttpTransact::HandleCacheOpenReadMiss(State* s)
   }
   // We do a cache lookup for DELETE and PUT requests as well.
   // We must, however, not cache the responses to these requests.
-  if (does_method_require_cache_copy_deletion(s->method) && s->api_req_cacheable == false) {
+  if (does_method_require_cache_copy_deletion(s->http_config_param, s->method) && s->api_req_cacheable == false) {
     s->cache_info.action = CACHE_DO_NO_ACTION;
   } else if ((s->hdr_info.client_request.presence(MIME_PRESENCE_RANGE) && !s->txn_conf->cache_range_write) ||
              s->range_setup == RANGE_NOT_SATISFIABLE || s->range_setup == RANGE_NOT_HANDLED) {
@@ -5747,7 +5748,7 @@ HttpTransact::is_cache_response_returnable(State* s)
     return false;
   }
 
-  if (!HttpTransactHeaders::is_method_cacheable(s->method) && s->api_resp_cacheable == false) {
+  if (!HttpTransactHeaders::is_method_cacheable(s->http_config_param, s->method) && s->api_resp_cacheable == false) {
     SET_VIA_STRING(VIA_CACHE_RESULT, VIA_IN_CACHE_NOT_ACCEPTABLE);
     SET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP, VIA_DETAIL_MISS_METHOD);
     return false;
@@ -6022,7 +6023,7 @@ HttpTransact::is_response_cacheable(State* s, HTTPHdr* request, HTTPHdr* respons
   // Basically, the problem is the resp for POST url1 req should not
   // be served to a GET url1 request, but we just match URL not method.
   int req_method = request->method_get_wksidx();
-  if (!(HttpTransactHeaders::is_method_cacheable(req_method)) && s->api_req_cacheable == false) {
+  if (!(HttpTransactHeaders::is_method_cacheable(s->http_config_param, req_method)) && s->api_req_cacheable == false) {
     DebugTxn("http_trans", "[is_response_cacheable] " "only GET, and some HEAD and POST are cachable");
     return false;
   }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2158d61d/proxy/http/HttpTransactHeaders.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransactHeaders.cc b/proxy/http/HttpTransactHeaders.cc
index 51af5cc..821b36c 100644
--- a/proxy/http/HttpTransactHeaders.cc
+++ b/proxy/http/HttpTransactHeaders.cc
@@ -31,9 +31,10 @@
 #include "I_Machine.h"
 
 bool
-HttpTransactHeaders::is_method_cacheable(int method)
+HttpTransactHeaders::is_method_cacheable(const HttpConfigParams *http_config_param, const int method)
 {
-  return (method == HTTP_WKSIDX_GET || method == HTTP_WKSIDX_HEAD);
+  return (method == HTTP_WKSIDX_GET || method == HTTP_WKSIDX_HEAD ||
+          (http_config_param->cache_post_method == 1 && method == HTTP_WKSIDX_POST));
 }
 
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2158d61d/proxy/http/HttpTransactHeaders.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransactHeaders.h b/proxy/http/HttpTransactHeaders.h
index 64df9bf..6170a75 100644
--- a/proxy/http/HttpTransactHeaders.h
+++ b/proxy/http/HttpTransactHeaders.h
@@ -32,7 +32,7 @@ class HttpTransactHeaders
 {
 public:
   static bool is_this_http_method_supported(int method);
-  static bool is_method_cacheable(int method);
+  static bool is_method_cacheable(const HttpConfigParams *http_config_param, const int method);
   static bool is_method_cache_lookupable(int method);
   static bool is_this_a_hop_by_hop_header(const char *field_name_wks);
   static bool is_this_method_supported(int the_scheme, int the_method);