Repository: trafficserver
Updated Branches:
  refs/heads/master 02ad63baf -> 71ba5925d


TS-3912: Consider Date header and response received time for conditional 
requests

Signed-off-by: Mark Torluemke <[email protected]>


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

Branch: refs/heads/master
Commit: c061b267086f6b93667812628dc183f245f54a8e
Parents: 02ad63b
Author: Phil Sorber <[email protected]>
Authored: Wed Sep 16 09:45:43 2015 -0600
Committer: Phil Sorber <[email protected]>
Committed: Wed Sep 16 10:03:43 2015 -0600

----------------------------------------------------------------------
 proxy/http/HttpTransact.cc      | 18 +++++++++--------
 proxy/http/HttpTransactCache.cc | 38 +++++++++++++++++++++++++-----------
 proxy/http/HttpTransactCache.h  |  3 ++-
 3 files changed, 39 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c061b267/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index ed20174..0737466 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -2822,7 +2822,8 @@ HttpTransact::build_response_from_cache(State *s, 
HTTPWarningCode warning_code)
   // the function match_response_to_request_conditionals() returns
   // the code of the cached response, which means that we should send
   // back the full document.
-  HTTPStatus client_response_code = 
HttpTransactCache::match_response_to_request_conditionals(client_request, 
cached_response);
+  HTTPStatus client_response_code =
+    HttpTransactCache::match_response_to_request_conditionals(client_request, 
cached_response, s->response_received_time);
 
   switch (client_response_code) {
   case HTTP_STATUS_NOT_MODIFIED:
@@ -4148,8 +4149,8 @@ 
HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
       client_response_code = base_response->status_get();
     } else if ((s->cache_info.action == CACHE_DO_DELETE) || 
((s->cache_info.action == CACHE_DO_UPDATE) && !cacheable)) {
       if (is_request_conditional(&s->hdr_info.client_request)) {
-        client_response_code = 
HttpTransactCache::match_response_to_request_conditionals(&s->hdr_info.client_request,
-                                                                               
          s->cache_info.object_read->response_get());
+        client_response_code = 
HttpTransactCache::match_response_to_request_conditionals(
+          &s->hdr_info.client_request, 
s->cache_info.object_read->response_get(), s->response_received_time);
       } else {
         client_response_code = HTTP_STATUS_OK;
       }
@@ -4182,7 +4183,7 @@ 
HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
       if (is_request_conditional(&s->hdr_info.client_request)) {
         if (s->txn_conf->cache_when_to_revalidate != 4)
           client_response_code = 
HttpTransactCache::match_response_to_request_conditionals(
-            &s->hdr_info.client_request, 
s->cache_info.object_read->response_get());
+            &s->hdr_info.client_request, 
s->cache_info.object_read->response_get(), s->response_received_time);
         else
           client_response_code = server_response_code;
       } else {
@@ -4300,8 +4301,9 @@ 
HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
       base_response->unset_cooked_cc_need_revalidate_once();
 
       if (is_request_conditional(&s->hdr_info.client_request) &&
-          HttpTransactCache::match_response_to_request_conditionals(
-            &s->hdr_info.client_request, 
s->cache_info.object_read->response_get()) == HTTP_STATUS_NOT_MODIFIED) {
+          
HttpTransactCache::match_response_to_request_conditionals(&s->hdr_info.client_request,
+                                                                    
s->cache_info.object_read->response_get(),
+                                                                    
s->response_received_time) == HTTP_STATUS_NOT_MODIFIED) {
         s->next_action = SM_ACTION_INTERNAL_CACHE_UPDATE_HEADERS;
         client_response_code = HTTP_STATUS_NOT_MODIFIED;
       } else {
@@ -4414,8 +4416,8 @@ 
HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
           resp->set_expires(exp_time);
         }
       } else if (is_request_conditional(&s->hdr_info.client_request) && 
server_response_code == HTTP_STATUS_OK) {
-        client_response_code =
-          
HttpTransactCache::match_response_to_request_conditionals(&s->hdr_info.client_request,
 &s->hdr_info.server_response);
+        client_response_code = 
HttpTransactCache::match_response_to_request_conditionals(
+          &s->hdr_info.client_request, &s->hdr_info.server_response, 
s->response_received_time);
 
         DebugTxn("http_trans", "[hcoofsr] conditional request, 200 "
                                "response, send back 304 if possible [crc=%d]",

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c061b267/proxy/http/HttpTransactCache.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransactCache.cc b/proxy/http/HttpTransactCache.cc
index 35e5f61..57c8559 100644
--- a/proxy/http/HttpTransactCache.cc
+++ b/proxy/http/HttpTransactCache.cc
@@ -1279,7 +1279,7 @@ HttpTransactCache::CalcVariability(CacheLookupHttpConfig 
*http_config_params, HT
 
 */
 HTTPStatus
-HttpTransactCache::match_response_to_request_conditionals(HTTPHdr *request, 
HTTPHdr *response)
+HttpTransactCache::match_response_to_request_conditionals(HTTPHdr *request, 
HTTPHdr *response, ink_time_t response_received_time)
 {
   HTTPStatus response_code = HTTP_STATUS_NONE;
 
@@ -1292,23 +1292,39 @@ 
HttpTransactCache::match_response_to_request_conditionals(HTTPHdr *request, HTTP
                           MIME_PRESENCE_IF_MATCH | MIME_PRESENCE_RANGE))) {
     return response->status_get();
   }
-  // return NOT_MODIFIED only if both If-modified-since and If-none-match fail
 
   // If-Modified-Since //
   if (request->presence(MIME_PRESENCE_IF_MODIFIED_SINCE)) {
-    // lm_value is zero if Last-modified not exists
-    ink_time_t lm_value = response->get_last_modified();
+    if (response->presence(MIME_PRESENCE_LAST_MODIFIED)) {
+      ink_time_t lm_value = response->get_last_modified();
+
+      // we won't return NOT_MODIFIED if Last-modified is too recent
+      if ((lm_value == 0) || (request->get_if_modified_since() < lm_value)) {
+        return response->status_get();
+      }
 
-    // we won't return NOT_MODIFIED if Last-modified not exists
-    if ((lm_value == 0) || (request->get_if_modified_since() < lm_value)) {
-      return response->status_get();
-    } else {
-      // we cannot return NOT_MODIFIED yet, need to check If-none-match
       response_code = HTTP_STATUS_NOT_MODIFIED;
+    } else if (response->presence(MIME_PRESENCE_DATE)) {
+      ink_time_t date_value = response->get_date();
+
+      // we won't return NOT_MODIFIED if Date is too recent
+      if ((date_value == 0) || (request->get_if_modified_since() < 
date_value)) {
+        return response->status_get();
+      }
 
-      if (!request->presence(MIME_PRESENCE_IF_NONE_MATCH)) {
-        return response_code;
+      response_code = HTTP_STATUS_NOT_MODIFIED;
+    } else {
+      // we won't return NOT_MODIFIED if received time is too recent
+      if (request->get_if_modified_since() < response_received_time) {
+        return response->status_get();
       }
+
+      response_code = HTTP_STATUS_NOT_MODIFIED;
+    }
+
+    // we cannot return NOT_MODIFIED yet, need to check If-none-match
+    if (!request->presence(MIME_PRESENCE_IF_NONE_MATCH)) {
+      return response_code;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c061b267/proxy/http/HttpTransactCache.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransactCache.h b/proxy/http/HttpTransactCache.h
index 7f20b59..c6ef7d1 100644
--- a/proxy/http/HttpTransactCache.h
+++ b/proxy/http/HttpTransactCache.h
@@ -129,7 +129,8 @@ public:
                                        HTTPHdr *obj_origin_server_response     
                            // in
                                        );
 
-  static HTTPStatus match_response_to_request_conditionals(HTTPHdr 
*ua_request, HTTPHdr *c_response);
+  static HTTPStatus match_response_to_request_conditionals(HTTPHdr 
*ua_request, HTTPHdr *c_response,
+                                                           ink_time_t 
response_received_time);
 };
 
 #endif

Reply via email to