diff --git a/doc/admin-guide/plugins/esi.en.rst b/doc/admin-guide/plugins/esi.en.rst index 757cab73284..5d1cdf507a5 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 diff --git a/plugins/experimental/esi/lib/Variables.cc b/plugins/experimental/esi/lib/Variables.cc index fbaaf069e14..02e03c4af45 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)); } } diff --git a/plugins/experimental/esi/lib/Variables.h b/plugins/experimental/esi/lib/Variables.h index d052d1eac48..9c498101f99 100644 --- a/plugins/experimental/esi/lib/Variables.h +++ b/plugins/experimental/esi/lib/Variables.h @@ -112,6 +112,7 @@ class Variables : private ComponentBase 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 @@ class Variables : private ComponentBase 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]; diff --git a/plugins/experimental/esi/test/vars_test.cc b/plugins/experimental/esi/test/vars_test.cc index 3adc021e475..9c6cf8748ab 100644 --- a/plugins/experimental/esi/test/vars_test.cc +++ b/plugins/experimental/esi/test/vars_test.cc @@ -401,6 +401,21 @@ 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; }