From 03293f1e65ccaf669bef288e6db4aff7a8d50e4e Mon Sep 17 00:00:00 2001 From: Petar Penkov Date: Wed, 24 Aug 2016 16:52:19 -0700 Subject: [PATCH] TS-4376: Support variable extension in set-header --- doc/admin-guide/plugins/header_rewrite.en.rst | 11 ++++------- plugins/header_rewrite/operators.cc | 6 ++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst index 18f83b25c71..0c5577cd067 100644 --- a/doc/admin-guide/plugins/header_rewrite.en.rst +++ b/doc/admin-guide/plugins/header_rewrite.en.rst @@ -503,9 +503,6 @@ only be specified once you may prefer to use `set-header`_ instead. The header's ```` may be specified as a literal string, or it may take advantage of `Variable Expansion`_ to calculate a dynamic value for the header. -In contrast, `set-header`_ does not support variable expansion for the header -value. If you wish to use variable expansion and avoid duplicate headers, you -may consider using an `rm-header`_ operator followed by `add-header`_. counter ~~~~~~~ @@ -607,8 +604,8 @@ set-header Replaces the value of header ```` with ````, creating the header if necessary. -Note that, unlike `add-header`_, this operator does not currently support -variable expansion. Values may only be specified according to `Header Values`_. +The header's ```` may be specified according to `Header Value`_ or take +advantage of `Variable Expansion`_ to calculate a dynamic value for the header. set-redirect ~~~~~~~~~~~~ @@ -694,8 +691,8 @@ QSA Append the results of the rule to the query string. Variable Expansion ------------------ -Only limited variable expansion is supported in `add-header`_. Supported -substitutions are currently: +Only limited variable expansion is supported in `add-header`_ and `set-header`_ +. Supported substitutions are currently: ============ ================================================================== Variable Description diff --git a/plugins/header_rewrite/operators.cc b/plugins/header_rewrite/operators.cc index 87a81a3f1fb..ce017fb4943 100644 --- a/plugins/header_rewrite/operators.cc +++ b/plugins/header_rewrite/operators.cc @@ -540,6 +540,12 @@ OperatorSetHeader::exec(const Resources &res) const _value.append_value(value, res); + if (_value.need_expansion()) { + VariableExpander ve(value); + + value = ve.expand(res); + } + // Never set an empty header (I don't think that ever makes sense?) if (value.empty()) { TSDebug(PLUGIN_NAME, "Would set header %s to an empty value, skipping", _header.c_str());