From 29cd601de30bd54b0c09fe9f30b274521c7b0103 Mon Sep 17 00:00:00 2001
From: Norm Paxton <npaxton@ldschurch.org>
Date: Thu, 13 Mar 2014 13:44:10 -0600
Subject: [PATCH] Invalidate PUT and POST

---
 proxy/http/HttpSM.h        | 6 +++++-
 proxy/http/HttpTransact.cc | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/proxy/http/HttpSM.h b/proxy/http/HttpSM.h
index 5cbfacb..0569a48 100644
--- a/proxy/http/HttpSM.h
+++ b/proxy/http/HttpSM.h
@@ -310,6 +310,9 @@ public:
   void set_http_schedule(Continuation *);
   int get_http_schedule(int event, void *data);
 
+  // NWP: Moved from protected, to allow call for invalidation for PUT and POST
+  void do_cache_delete_all_alts(Continuation * cont);
+  
 protected:
   IOBufferReader * ua_buffer_reader;
   IOBufferReader * ua_raw_buffer_reader;
@@ -412,7 +415,8 @@ protected:
   void do_cache_prepare_update();
   void do_cache_prepare_action(HttpCacheSM * c_sm,
                                CacheHTTPInfo * object_read_info, bool retry, bool allow_multiple = false);
-  void do_cache_delete_all_alts(Continuation * cont);
+  // NWP: Move to public, to allow call for invalidation for PUT and POST
+  //void do_cache_delete_all_alts(Continuation * cont);
   void do_icp_lookup();
   void do_auth_callout();
   void do_api_callout();
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 991e1bf..bbccf82 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -2317,6 +2317,15 @@ HttpTransact::HandleCacheOpenReadHitFreshness(State* s)
   if (s->cache_lookup_result == HttpTransact::CACHE_LOOKUP_HIT_STALE)
     SET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP, VIA_DETAIL_MISS_EXPIRED);
 
+  // NWP: if PUT or POST, then must invalidate all alternates in the cache, then continue to serve the request as sent
+  if (s->method == HTTP_WKSIDX_POST || s->method == HTTP_WKSIDX_PUT) {
+    s->state_machine->get_cache_sm().end_both();
+	s->state_machine->do_cache_delete_all_alts(NULL);
+	// NWP:  alternate way - using the state machine instead of direct call:  need to figure out the right return value
+	// s->cache_info.action = CACHE_DO_DELETE;  **** What is correct value here?
+	// s->next_action = HttpTransact::PROXY_INTERNAL_CACHE_DELETE   **** What is correct value here?
+	// TRANSACT_RETURN(PROXY_INTERNAL_CACHE_DELETE, HttpTransact::HandleCacheOpenReadMiss);   **** What are correct values here?
+  }
   if (!s->force_dns) {          // If DNS is not performed before
     if (need_to_revalidate(s)) {
       TRANSACT_RETURN(HTTP_API_CACHE_LOOKUP_COMPLETE, CallOSDNSLookup); // content needs to be revalidated and we did not perform a dns ....calling DNS lookup
-- 
1.8.4.msysgit.0

