You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2021/10/14 19:30:37 UTC
[trafficserver] branch 9.2.x updated (2f32d81 -> ea99681)
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a change to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git.
from 2f32d81 Updated ChangeLog
new f34613f Add set-body ability to header rewrite (#8411)
new ea99681 Remove operatorbody class, its not needed at this time (#8424)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
doc/admin-guide/plugins/header_rewrite.en.rst | 8 ++++++++
plugins/header_rewrite/factory.cc | 2 ++
plugins/header_rewrite/operators.cc | 26 ++++++++++++++++++++++++++
plugins/header_rewrite/operators.h | 19 +++++++++++++++++++
4 files changed, 55 insertions(+)
[trafficserver] 01/02: Add set-body ability to header rewrite
(#8411)
Posted by zw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit f34613f72002a9a4efbafeec6f01e63ba1c613b3
Author: Evan Zelkowitz <ez...@apache.org>
AuthorDate: Tue Oct 12 17:36:48 2021 -0600
Add set-body ability to header rewrite (#8411)
(cherry picked from commit d91620daf2247ec0a701ffee65a1bd24ec5eedef)
---
doc/admin-guide/plugins/header_rewrite.en.rst | 8 ++++++++
plugins/header_rewrite/factory.cc | 2 ++
plugins/header_rewrite/operator.cc | 7 +++++++
plugins/header_rewrite/operator.h | 19 +++++++++++++++++++
plugins/header_rewrite/operators.cc | 27 +++++++++++++++++++++++++++
plugins/header_rewrite/operators.h | 19 +++++++++++++++++++
6 files changed, 82 insertions(+)
diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst
index 420a1fb..b759ebe 100644
--- a/doc/admin-guide/plugins/header_rewrite.en.rst
+++ b/doc/admin-guide/plugins/header_rewrite.en.rst
@@ -650,6 +650,14 @@ rm-cookie
Removes the cookie ``<name>``.
+set-body
+~~~~~~~~
+::
+
+ set-body <text>
+
+Sets the body to ``<text>``. Can also be used to delete a body with ``""``
+
set-config
~~~~~~~~~~
::
diff --git a/plugins/header_rewrite/factory.cc b/plugins/header_rewrite/factory.cc
index 7f9d35c..6ad3d51 100644
--- a/plugins/header_rewrite/factory.cc
+++ b/plugins/header_rewrite/factory.cc
@@ -71,6 +71,8 @@ operator_factory(const std::string &op)
o = new OperatorSetConnMark();
} else if (op == "set-debug") {
o = new OperatorSetDebug();
+ } else if (op == "set-body") {
+ o = new OperatorSetBody();
} else {
TSError("[%s] Unknown operator: %s", PLUGIN_NAME, op.c_str());
return nullptr;
diff --git a/plugins/header_rewrite/operator.cc b/plugins/header_rewrite/operator.cc
index 1afab77..da1fdf6 100644
--- a/plugins/header_rewrite/operator.cc
+++ b/plugins/header_rewrite/operator.cc
@@ -70,3 +70,10 @@ OperatorCookies::initialize(Parser &p)
require_resources(RSRC_SERVER_REQUEST_HEADERS);
require_resources(RSRC_CLIENT_REQUEST_HEADERS);
}
+
+void
+OperatorBody::initialize(Parser &p)
+{
+ Operator::initialize(p);
+ _value = p.get_arg();
+}
diff --git a/plugins/header_rewrite/operator.h b/plugins/header_rewrite/operator.h
index 04821fc..9e1006d 100644
--- a/plugins/header_rewrite/operator.h
+++ b/plugins/header_rewrite/operator.h
@@ -88,6 +88,25 @@ protected:
};
///////////////////////////////////////////////////////////////////////////////
+// Base class for all Body based Operators, this is obviously also an
+// Operator interface.
+//
+class OperatorBody : public Operator
+{
+public:
+ OperatorBody() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorBody"); }
+
+ // noncopyable
+ OperatorBody(const OperatorBody &) = delete;
+ void operator=(const OperatorBody &) = delete;
+
+ void initialize(Parser &p) override;
+
+protected:
+ std::string _value;
+};
+
+///////////////////////////////////////////////////////////////////////////////
// Base class for all Cookie based Operators, this is obviously also an
// Operator interface.
//
diff --git a/plugins/header_rewrite/operators.cc b/plugins/header_rewrite/operators.cc
index 960884b..2b3e9c0 100644
--- a/plugins/header_rewrite/operators.cc
+++ b/plugins/header_rewrite/operators.cc
@@ -677,6 +677,33 @@ OperatorSetHeader::exec(const Resources &res) const
}
}
+// OperatorSetBody
+void
+OperatorSetBody::initialize(Parser &p)
+{
+ OperatorBody::initialize(p);
+
+ // we want the arg since body only takes one value
+ _value.set_value(p.get_arg());
+}
+
+void
+OperatorSetBody::initialize_hooks()
+{
+ add_allowed_hook(TS_HTTP_READ_RESPONSE_HDR_HOOK);
+ add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK);
+}
+
+void
+OperatorSetBody::exec(const Resources &res) const
+{
+ std::string value;
+
+ _value.append_value(value, res);
+ char *msg = TSstrdup(_value.get_value().c_str());
+ TSHttpTxnErrorBodySet(res.txnp, msg, _value.size(), nullptr);
+}
+
// OperatorCounter
void
OperatorCounter::initialize(Parser &p)
diff --git a/plugins/header_rewrite/operators.h b/plugins/header_rewrite/operators.h
index c79bd61..9df647c 100644
--- a/plugins/header_rewrite/operators.h
+++ b/plugins/header_rewrite/operators.h
@@ -404,3 +404,22 @@ protected:
void initialize_hooks() override;
void exec(const Resources &res) const override;
};
+
+class OperatorSetBody : public OperatorBody
+{
+public:
+ OperatorSetBody() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorSetBody"); }
+
+ // noncopyable
+ OperatorSetBody(const OperatorSetBody &) = delete;
+ void operator=(const OperatorSetBody &) = delete;
+
+ void initialize(Parser &p) override;
+
+protected:
+ void initialize_hooks() override;
+ void exec(const Resources &res) const override;
+
+private:
+ Value _value;
+};
[trafficserver] 02/02: Remove operatorbody class,
its not needed at this time (#8424)
Posted by zw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit ea99681d21b733325f66753fe0b0d21e2e46b29e
Author: Evan Zelkowitz <ez...@apache.org>
AuthorDate: Thu Oct 14 11:16:37 2021 -0600
Remove operatorbody class, its not needed at this time (#8424)
(cherry picked from commit bb431907fa35b786185b52a512af03b0776365c3)
---
plugins/header_rewrite/operator.cc | 7 -------
plugins/header_rewrite/operator.h | 19 -------------------
plugins/header_rewrite/operators.cc | 3 +--
plugins/header_rewrite/operators.h | 2 +-
4 files changed, 2 insertions(+), 29 deletions(-)
diff --git a/plugins/header_rewrite/operator.cc b/plugins/header_rewrite/operator.cc
index da1fdf6..1afab77 100644
--- a/plugins/header_rewrite/operator.cc
+++ b/plugins/header_rewrite/operator.cc
@@ -70,10 +70,3 @@ OperatorCookies::initialize(Parser &p)
require_resources(RSRC_SERVER_REQUEST_HEADERS);
require_resources(RSRC_CLIENT_REQUEST_HEADERS);
}
-
-void
-OperatorBody::initialize(Parser &p)
-{
- Operator::initialize(p);
- _value = p.get_arg();
-}
diff --git a/plugins/header_rewrite/operator.h b/plugins/header_rewrite/operator.h
index 9e1006d..04821fc 100644
--- a/plugins/header_rewrite/operator.h
+++ b/plugins/header_rewrite/operator.h
@@ -88,25 +88,6 @@ protected:
};
///////////////////////////////////////////////////////////////////////////////
-// Base class for all Body based Operators, this is obviously also an
-// Operator interface.
-//
-class OperatorBody : public Operator
-{
-public:
- OperatorBody() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorBody"); }
-
- // noncopyable
- OperatorBody(const OperatorBody &) = delete;
- void operator=(const OperatorBody &) = delete;
-
- void initialize(Parser &p) override;
-
-protected:
- std::string _value;
-};
-
-///////////////////////////////////////////////////////////////////////////////
// Base class for all Cookie based Operators, this is obviously also an
// Operator interface.
//
diff --git a/plugins/header_rewrite/operators.cc b/plugins/header_rewrite/operators.cc
index 2b3e9c0..90b89bc 100644
--- a/plugins/header_rewrite/operators.cc
+++ b/plugins/header_rewrite/operators.cc
@@ -681,8 +681,7 @@ OperatorSetHeader::exec(const Resources &res) const
void
OperatorSetBody::initialize(Parser &p)
{
- OperatorBody::initialize(p);
-
+ Operator::initialize(p);
// we want the arg since body only takes one value
_value.set_value(p.get_arg());
}
diff --git a/plugins/header_rewrite/operators.h b/plugins/header_rewrite/operators.h
index 9df647c..c2ddf79 100644
--- a/plugins/header_rewrite/operators.h
+++ b/plugins/header_rewrite/operators.h
@@ -405,7 +405,7 @@ protected:
void exec(const Resources &res) const override;
};
-class OperatorSetBody : public OperatorBody
+class OperatorSetBody : public Operator
{
public:
OperatorSetBody() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for OperatorSetBody"); }