Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/admin-guide/plugins/esi.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 3 additions & 4 deletions plugins/experimental/esi/lib/Variables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/experimental/esi/lib/Variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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];
Expand Down
15 changes: 15 additions & 0 deletions plugins/experimental/esi/test/vars_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}