Repository: trafficserver Updated Branches: refs/heads/master a4bc60ee8 -> a090b1a08
TS-3966 header_rewrite now allows pre-origin requests to be denied This generalizes the concept of set-status, such that it also works in remap read-request hooks. I.e. prior to having a status code from cache / origin. This avoids going to origin before we can reject a request. This closes ##346. Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/a090b1a0 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/a090b1a0 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/a090b1a0 Branch: refs/heads/master Commit: a090b1a0805887387615e5936f4410f4a9955e4a Parents: a4bc60e Author: Leif Hedstrom <[email protected]> Authored: Tue Oct 20 12:17:32 2015 -0600 Committer: Leif Hedstrom <[email protected]> Committed: Mon Nov 30 09:09:24 2015 -0700 ---------------------------------------------------------------------- plugins/header_rewrite/operators.cc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a090b1a0/plugins/header_rewrite/operators.cc ---------------------------------------------------------------------- diff --git a/plugins/header_rewrite/operators.cc b/plugins/header_rewrite/operators.cc index 5ce75f5..4c634cb 100644 --- a/plugins/header_rewrite/operators.cc +++ b/plugins/header_rewrite/operators.cc @@ -97,17 +97,31 @@ OperatorSetStatus::initialize_hooks() { add_allowed_hook(TS_HTTP_READ_RESPONSE_HDR_HOOK); add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK); + add_allowed_hook(TS_HTTP_READ_REQUEST_HDR_HOOK); + add_allowed_hook(TS_HTTP_READ_REQUEST_PRE_REMAP_HOOK); + add_allowed_hook(TS_REMAP_PSEUDO_HOOK); } void OperatorSetStatus::exec(const Resources &res) const { - if (res.bufp && res.hdr_loc) { - TSHttpHdrStatusSet(res.bufp, res.hdr_loc, (TSHttpStatus)_status.get_int_value()); - if (_reason && _reason_len > 0) - TSHttpHdrReasonSet(res.bufp, res.hdr_loc, _reason, _reason_len); + switch (get_hook()) { + case TS_HTTP_READ_RESPONSE_HDR_HOOK: + case TS_HTTP_SEND_RESPONSE_HDR_HOOK: + if (res.bufp && res.hdr_loc) { + TSHttpHdrStatusSet(res.bufp, res.hdr_loc, (TSHttpStatus)_status.get_int_value()); + if (_reason && _reason_len > 0) { + TSHttpHdrReasonSet(res.bufp, res.hdr_loc, _reason, _reason_len); + } + } + break; + default: + TSHttpTxnSetHttpRetStatus(res.txnp, (TSHttpStatus)_status.get_int_value()); + break; } + + TSDebug(PLUGIN_NAME, "OperatorSetStatus::exec() invoked with status=%d", _status.get_int_value()); }
