Repository: trafficserver
Updated Branches:
  refs/heads/master 2f0440f10 -> e54dd3a3a


[TS-3398]: Enhance header_rewrite to support METHOD as a condition


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/c7943921
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/c7943921
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/c7943921

Branch: refs/heads/master
Commit: c79439212794f2d2df1db20b2278ac1fb96b1558
Parents: 2f0440f
Author: Sudheer Vinukonda <[email protected]>
Authored: Fri Feb 20 16:14:15 2015 +0000
Committer: Sudheer Vinukonda <[email protected]>
Committed: Fri Feb 20 16:14:15 2015 +0000

----------------------------------------------------------------------
 plugins/header_rewrite/conditions.cc | 43 +++++++++++++++++++++++++++++++
 plugins/header_rewrite/conditions.h  | 19 ++++++++++++++
 plugins/header_rewrite/factory.cc    |  2 ++
 3 files changed, 64 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c7943921/plugins/header_rewrite/conditions.cc
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/conditions.cc 
b/plugins/header_rewrite/conditions.cc
index be3d28b..04fb456 100644
--- a/plugins/header_rewrite/conditions.cc
+++ b/plugins/header_rewrite/conditions.cc
@@ -72,6 +72,49 @@ ConditionStatus::append_value(std::string& s, const 
Resources& res)
 }
 
 
+// ConditionMethod
+void
+ConditionMethod::initialize(Parser& p)
+{
+  Condition::initialize(p);
+
+  Matchers<std::string>* match = new Matchers<std::string>(_cond_op);
+  match->set(p.get_arg());
+
+  _matcher = match;
+}
+
+bool
+ConditionMethod::eval(const Resources& res)
+{
+  std::string s;
+
+  append_value(s, res);
+  bool rval = static_cast<const Matchers<std::string>*>(_matcher)->test(s);
+  TSDebug(PLUGIN_NAME, "Evaluating METHOD(): %s - rval: %d", s.c_str(), rval);
+  return rval;
+}
+
+
+void
+ConditionMethod::append_value(std::string& s, const Resources& res)
+{
+  TSMBuffer bufp;
+  TSMLoc hdr_loc;
+  const char* value;
+  int len;
+
+  bufp = res.client_bufp;
+  hdr_loc = res.client_hdr_loc;
+
+  if (bufp && hdr_loc) {
+    value = TSHttpHdrMethodGet(bufp, hdr_loc, &len);
+    TSDebug(PLUGIN_NAME, "Appending METHOD(%s) to evaluation value -> %.*s", 
_qualifier.c_str(), len, value);
+    s.append(value, len);
+  }
+}
+
+
 // ConditionRandom: random 0 to (N-1)
 void
 ConditionRandom::initialize(Parser& p)

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c7943921/plugins/header_rewrite/conditions.h
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/conditions.h 
b/plugins/header_rewrite/conditions.h
index fbb843d..f540df1 100644
--- a/plugins/header_rewrite/conditions.h
+++ b/plugins/header_rewrite/conditions.h
@@ -101,6 +101,25 @@ private:
 };
 
 
+// Check the HTTP method
+class ConditionMethod : public Condition
+{
+public:
+  ConditionMethod()
+  {
+    TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionMethod");
+  }
+  void initialize(Parser& p);
+  void append_value(std::string& s, const Resources& res);
+
+protected:
+  bool eval(const Resources& res);
+
+private:
+  DISALLOW_COPY_AND_ASSIGN(ConditionMethod);
+};
+
+
 // Random 0 to (N-1)
 class ConditionRandom : public Condition
 {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c7943921/plugins/header_rewrite/factory.cc
----------------------------------------------------------------------
diff --git a/plugins/header_rewrite/factory.cc 
b/plugins/header_rewrite/factory.cc
index eb44369..eeff0aa 100644
--- a/plugins/header_rewrite/factory.cc
+++ b/plugins/header_rewrite/factory.cc
@@ -115,6 +115,8 @@ condition_factory(const std::string& cond)
     c = new ConditionClientIp();
   } else if (c_name == "INCOMING-PORT") {
     c = new ConditionIncomingPort();
+  } else if (c_name == "METHOD") {
+    c = new ConditionMethod();
   } else {
     TSError("%s: unknown condition: %s", PLUGIN_NAME, c_name.c_str());
     return NULL;

Reply via email to