Skip to content
Open
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
4 changes: 2 additions & 2 deletions include/proxy/hdrs/HTTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ inline void
HTTPHdr::status_set(HTTPStatus status)
{
ink_assert(valid());
ink_assert(m_http->m_polarity == HTTP_TYPE_RESPONSE);
ink_release_assert(m_http->m_polarity == HTTP_TYPE_RESPONSE);

http_hdr_status_set(m_http, status);
}
Expand All @@ -1115,7 +1115,7 @@ inline void
HTTPHdr::reason_set(const char *value, int length)
{
ink_assert(valid());
ink_assert(m_http->m_polarity == HTTP_TYPE_RESPONSE);
ink_release_assert(m_http->m_polarity == HTTP_TYPE_RESPONSE);

http_hdr_reason_set(m_heap, m_http, value, length, true);
}
Expand Down
18 changes: 6 additions & 12 deletions plugins/header_rewrite/operators.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,13 @@ OperatorSetStatus::initialize_hooks()
bool
OperatorSetStatus::exec(const Resources &res) const
{
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, static_cast<TSHttpStatus>(_status.get_int_value()));
if (_reason && _reason_len > 0) {
TSHttpHdrReasonSet(res.bufp, res.hdr_loc, _reason, _reason_len);
}
if (res.bufp && res.hdr_loc && TSHttpHdrTypeGet(res.bufp, res.hdr_loc) == TS_HTTP_TYPE_RESPONSE) {
TSHttpHdrStatusSet(res.bufp, res.hdr_loc, static_cast<TSHttpStatus>(_status.get_int_value()));
if (_reason && _reason_len > 0) {
TSHttpHdrReasonSet(res.bufp, res.hdr_loc, _reason, _reason_len);
}
break;
default:
} else {
TSHttpTxnStatusSet(res.state.txnp, static_cast<TSHttpStatus>(_status.get_int_value()));
break;
}

Dbg(pi_dbg_ctl, "OperatorSetStatus::exec() invoked with status=%d", _status.get_int_value());
Expand Down Expand Up @@ -602,7 +596,7 @@ OperatorSetRedirect::exec(const Resources &res) const
const_cast<Resources &>(res).changed_url = true;
res._rri->redirect = 1;
} else {
Dbg(pi_dbg_ctl, "OperatorSetRedirect::exec() hook=%d", int(get_hook()));
Dbg(pi_dbg_ctl, "OperatorSetRedirect::exec() redirect to %s", value.c_str());
// Set the new status code and reason.
TSHttpStatus status = static_cast<TSHttpStatus>(_status.get_int_value());
TSHttpHdrStatusSet(res.bufp, res.hdr_loc, status);
Expand Down
4 changes: 2 additions & 2 deletions plugins/header_rewrite/ruleset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ RuleSet::make_condition(Parser &p, const char *filename, int lineno)
Dbg(pi_dbg_ctl, " Creating condition: %%{%s} with arg: %s", p.get_op().c_str(), p.get_arg().c_str());
c->set_config_location(filename, lineno);
c->initialize(p);
if (!c->set_hook(_hook)) {
if (!c->is_hook_valid(_hook)) {
delete c;
TSError("[%s] in %s:%d: can't use this condition in hook=%s: %%{%s} with arg: %s", PLUGIN_NAME, filename, lineno,
TSHttpHookNameLookup(_hook), p.get_op().c_str(), p.get_arg().c_str());
Expand Down Expand Up @@ -82,7 +82,7 @@ RuleSet::add_operator(Parser &p, const char *filename, int lineno)
Dbg(pi_dbg_ctl, " Adding operator: %s(%s)=\"%s\"", p.get_op().c_str(), p.get_arg().c_str(), p.get_value().c_str());
op->set_config_location(filename, lineno);
op->initialize(p);
if (!op->set_hook(_hook)) {
if (!op->is_hook_valid(_hook)) {
delete op;
Dbg(pi_dbg_ctl, "in %s:%d: can't use this operator in hook=%s: %s(%s)", filename, lineno, TSHttpHookNameLookup(_hook),
p.get_op().c_str(), p.get_arg().c_str());
Expand Down
10 changes: 2 additions & 8 deletions plugins/header_rewrite/statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ Statement::get_resource_ids() const
}

bool
Statement::set_hook(TSHttpHookID hook)
Statement::is_hook_valid(TSHttpHookID hook) const
{
bool ret = std::find(_allowed_hooks.begin(), _allowed_hooks.end(), hook) != _allowed_hooks.end();

if (ret) {
_hook = hook;
}

return ret;
return std::find(_allowed_hooks.begin(), _allowed_hooks.end(), hook) != _allowed_hooks.end();
}

// This should be overridden for any Statement which only supports some hooks
Expand Down
10 changes: 2 additions & 8 deletions plugins/header_rewrite/statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,8 @@ class Statement
Statement(const Statement &) = delete;
void operator=(const Statement &) = delete;

// Which hook are we adding this statement to?
bool set_hook(TSHttpHookID hook);
TSHttpHookID
get_hook() const
{
return _hook;
}
// Validate that this statement is allowed on the given hook. Used during parsing only.
bool is_hook_valid(TSHttpHookID hook) const;

// Which hooks are this "statement" applicable for? Used during parsing only.
void
Expand Down Expand Up @@ -244,7 +239,6 @@ class Statement

private:
ResourceIDs _rsrc = RSRC_NONE;
TSHttpHookID _hook = TS_HTTP_READ_RESPONSE_HDR_HOOK;
std::vector<TSHttpHookID> _allowed_hooks;
std::string _config_filename;
int _config_lineno = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/proxy/hdrs/HTTP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ http_hdr_url_set(HdrHeap *heap, HTTPHdrImpl *hh, URLImpl *url)
void
http_hdr_status_set(HTTPHdrImpl *hh, HTTPStatus status)
{
ink_assert(hh->m_polarity == HTTP_TYPE_RESPONSE);
ink_release_assert(hh->m_polarity == HTTP_TYPE_RESPONSE);
hh->u.resp.m_status = status;
}

Expand All @@ -775,7 +775,7 @@ http_hdr_reason_get(HTTPHdrImpl *hh, int *length)
void
http_hdr_reason_set(HdrHeap *heap, HTTPHdrImpl *hh, const char *value, int length, bool must_copy)
{
ink_assert(hh->m_polarity == HTTP_TYPE_RESPONSE);
ink_release_assert(hh->m_polarity == HTTP_TYPE_RESPONSE);
mime_str_u16_set(heap, value, length, &(hh->u.resp.m_ptr_reason), &(hh->u.resp.m_len_reason), must_copy);
}

Expand Down