From 702d93558772029c150248f09263f1716e56864d Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 20 Oct 2015 12:17:32 -0600 Subject: [PATCH] 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. --- plugins/header_rewrite/operators.cc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/header_rewrite/operators.cc b/plugins/header_rewrite/operators.cc index 5ce75f5985e..4c634cb03b5 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()); }