You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2015/12/21 20:44:54 UTC

[03/16] trafficserver git commit: TS-4079: Support for arbitrary esi vars through HTTP request headers. This closes #378

TS-4079: Support for arbitrary esi vars through HTTP request headers. This closes #378


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

Branch: refs/heads/6.1.x
Commit: 7773395bc218b26890f01e0ef12b576a13416fdb
Parents: 64957d4
Author: Sandeep Davu <sa...@gmail.com>
Authored: Thu Dec 17 23:59:14 2015 +0000
Committer: Kit Chan <ki...@apache.org>
Committed: Thu Dec 17 23:59:14 2015 +0000

----------------------------------------------------------------------
 doc/admin-guide/plugins/esi.en.rst         |  3 +++
 plugins/experimental/esi/lib/Variables.cc  |  5 ++---
 plugins/experimental/esi/lib/Variables.h   |  3 ++-
 plugins/experimental/esi/test/vars_test.cc | 14 ++++++++++++++
 4 files changed, 21 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7773395b/doc/admin-guide/plugins/esi.en.rst
----------------------------------------------------------------------
diff --git a/doc/admin-guide/plugins/esi.en.rst b/doc/admin-guide/plugins/esi.en.rst
index 757cab7..5d1cdf5 100644
--- a/doc/admin-guide/plugins/esi.en.rst
+++ b/doc/admin-guide/plugins/esi.en.rst
@@ -53,6 +53,7 @@ Supported variables:
     $(HTTP_ACCEPT_LANGUAGE{name})
     $(HTTP_COOKIE{name}) or $(HTTP_COOKIE{name;subkey})
     $(QUERY_STRING{name})
+    $(HTTP_HEADER{hdr_name})
 
 Note: the name is the key name such as "username", "id" etc. For cookie support sub-name or sub-key, the format is:
 name;subkey, such as "l;u", "l;t" etc. e.g. such cookie string: l=u=test&t=1350952328, the value of
@@ -149,3 +150,5 @@ Differences from Spec - http://www.w3.org/TR/esi-lang
 4. HTTP_USER_AGENT variable is not supported
 
 5. HTTP_COOKIE supports fetching for sub-key
+
+6. HTTP_HEADER supports accessing request headers as variables

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7773395b/plugins/experimental/esi/lib/Variables.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/esi/lib/Variables.cc b/plugins/experimental/esi/lib/Variables.cc
index fbaaf06..3d77173 100644
--- a/plugins/experimental/esi/lib/Variables.cc
+++ b/plugins/experimental/esi/lib/Variables.cc
@@ -45,7 +45,7 @@ const string Variables::SPECIAL_HEADERS[] = {string("ACCEPT-LANGUAGE"), string("
 const string Variables::NORM_SIMPLE_HEADERS[] = {string("HTTP_HOST"), string("HTTP_REFERER"), string("")};
 
 const string Variables::NORM_SPECIAL_HEADERS[] = {string("HTTP_ACCEPT_LANGUAGE"), string("HTTP_COOKIE"), string("HTTP_USER_AGENT"),
-                                                  string("QUERY_STRING"), string("")};
+                                                  string("QUERY_STRING"),         string("HTTP_HEADER"), string("")};
 
 inline string &
 Variables::_toUpperCase(string &str) const
@@ -106,11 +106,10 @@ Variables::populate(const HttpHeader &header)
         match_index = _searchHeaders(SPECIAL_HEADERS, header.name, name_len);
         if (match_index != -1) {
           _cached_special_headers[match_index].push_back(string(header.value, value_len));
-        } else {
-          _debugLog(_debug_tag, "[%s] Not retaining header [%.*s]", __FUNCTION__, name_len, header.name);
         }
       }
     }
+    _insert(_dict_data[HTTP_HEADER], string(header.name, name_len), string(header.value, value_len));
   }
 }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7773395b/plugins/experimental/esi/lib/Variables.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/esi/lib/Variables.h b/plugins/experimental/esi/lib/Variables.h
index d052d1e..d5407f8 100644
--- a/plugins/experimental/esi/lib/Variables.h
+++ b/plugins/experimental/esi/lib/Variables.h
@@ -112,6 +112,7 @@ private:
     HTTP_COOKIE = 1,
     HTTP_USER_AGENT = 2,
     QUERY_STRING = 3,
+    HTTP_HEADER = 4,
   };
   static const std::string SPECIAL_HEADERS[]; // indices should map to enum values above
 
@@ -120,7 +121,7 @@ private:
   static const std::string NORM_SPECIAL_HEADERS[]; // indices should again map to enum values
 
   static const int N_SIMPLE_HEADERS = HTTP_REFERER + 1;
-  static const int N_SPECIAL_HEADERS = QUERY_STRING + 1;
+  static const int N_SPECIAL_HEADERS = HTTP_HEADER + 1;
 
   StringHash _simple_data;
   StringHash _dict_data[N_SPECIAL_HEADERS];

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7773395b/plugins/experimental/esi/test/vars_test.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/esi/test/vars_test.cc b/plugins/experimental/esi/test/vars_test.cc
index 3adc021..a17023b 100644
--- a/plugins/experimental/esi/test/vars_test.cc
+++ b/plugins/experimental/esi/test/vars_test.cc
@@ -401,6 +401,20 @@ main()
     assert(esi_vars.getValue("HTTP_COOKIE{Y;intl}") == "");
   }
 
+  {
+    cout << endl << "===================== Test 5" << endl;
+    Variables esi_vars("vars_test", &Debug, &Error);
+    esi_vars.populate(HttpHeader("hdr1", -1, "hval1", -1));
+    esi_vars.populate(HttpHeader("Hdr2", -1, "hval2", -1));
+    esi_vars.populate(HttpHeader("@Intenal-hdr1", -1, "internal-hval1", -1));
+
+    assert(esi_vars.getValue("HTTP_HEADER{hdr1}") == "hval1");
+    assert(esi_vars.getValue("HTTP_HEADER{hdr2}") == "");
+    assert(esi_vars.getValue("HTTP_HEADER{Hdr2}") == "hval2");
+    assert(esi_vars.getValue("HTTP_HEADER{non-existent}") == "");
+    assert(esi_vars.getValue("HTTP_HEADER{@Intenal-hdr1}") == "internal-hval1");
+  }
+
   cout << endl << "All tests passed!" << endl;
   return 0;
 }