Skip to content
Merged
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
11 changes: 10 additions & 1 deletion plugins/header_rewrite/header_rewrite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ cont_rewrite_headers(TSCont contp, TSEvent event, void *edata)
break;
}

bool reenable{true};
if (hook != TS_HTTP_LAST_HOOK) {
const RuleSet *rule = conf->rule(hook);
Resources res(txnp, contp);
Expand All @@ -311,6 +312,10 @@ cont_rewrite_headers(TSCont contp, TSEvent event, void *edata)
if (rule->eval(res)) {
OperModifiers rt = rule->exec(res);

if (rt & OPER_NO_REENABLE) {
reenable = false;
}

if (rule->last() || (rt & OPER_LAST)) {
break; // Conditional break, force a break with [L]
}
Expand All @@ -319,7 +324,9 @@ cont_rewrite_headers(TSCont contp, TSEvent event, void *edata)
}
}

TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
if (reenable) {
TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
}
return 0;
}

Expand Down Expand Up @@ -523,6 +530,8 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
if (rule->eval(res)) {
OperModifiers rt = rule->exec(res);

ink_assert((rt & OPER_NO_REENABLE) == 0);

if (res.changed_url == true) {
rval = TSREMAP_DID_REMAP;
}
Expand Down
26 changes: 17 additions & 9 deletions plugins/header_rewrite/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@

// Operator modifiers
enum OperModifiers {
OPER_NONE = 0,
OPER_LAST = 1,
OPER_NEXT = 2,
OPER_QSA = 4,
OPER_INV = 8,
OPER_NONE = 0,
OPER_LAST = 1,
OPER_NEXT = 2,
OPER_QSA = 4,
OPER_INV = 8,
OPER_NO_REENABLE = 16,
};

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -55,17 +56,24 @@ class Operator : public Statement
OperModifiers get_oper_modifiers() const;
void initialize(Parser &p) override;

void
// Returns number of executed operators that need to defer call to TSHttpTxnReenable(). It is a fatal error if this
// returns more than 1. If multiple operators need to defer reenable on the same hook, issue 11549 should be
// revisited. In this case, one possible approach would be to add a per-transaction user parameter, pointing to
// a count of operators that are deferred the reeanable for a particular hook.
unsigned
do_exec(const Resources &res) const
{
exec(res);
unsigned no_reenable{exec(res) ? 0U : 1U};
if (nullptr != _next) {
static_cast<Operator *>(_next)->do_exec(res);
no_reenable += static_cast<Operator *>(_next)->do_exec(res);
}
return no_reenable;
}

protected:
virtual void exec(const Resources &res) const = 0;
// Return false to disable call of TSHttpTxnReenable(). Operators executed in the remap pseudo-hook MUST return true,
// as reenable is implicit in remap execution.
virtual bool exec(const Resources &res) const = 0;

private:
OperModifiers _mods = OPER_NONE;
Expand Down
Loading