sudheerv commented on a change in pull request #7516:
URL: https://github.com/apache/trafficserver/pull/7516#discussion_r605014663



##########
File path: plugins/header_rewrite/conditions.cc
##########
@@ -1333,4 +1344,71 @@ ConditionSessionTransactCount::append_value(std::string 
&s, Resources const &res
     TSDebug(PLUGIN_NAME, "Appending SSN-TXN-COUNT %s to evaluation value 
%.*s", _qualifier.c_str(), length, value);
     s.append(value, length);
   }
-}
\ No newline at end of file
+}
+
+void
+ConditionTcpInfo::initialize(Parser &p)
+{
+  Condition::initialize(p);
+  TSDebug(PLUGIN_NAME, "Initializing TCP Info");
+  MatcherType *match     = new MatcherType(_cond_op);
+  std::string const &arg = p.get_arg();
+
+  match->set(strtol(arg.c_str(), nullptr, 10));
+  _matcher = match;
+}
+
+void
+ConditionTcpInfo::initialize_hooks()
+{
+  add_allowed_hook(TS_HTTP_TXN_START_HOOK);
+  add_allowed_hook(TS_HTTP_TXN_CLOSE_HOOK);
+  add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK);
+}
+
+bool
+ConditionTcpInfo::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 TCP-Info: %s - rval: %d", s.c_str(), rval);
+
+  return rval;
+}
+
+void
+ConditionTcpInfo::append_value(std::string &s, Resources const &res)
+{
+#if defined(TCP_INFO) && defined(HAVE_STRUCT_TCP_INFO)
+  TSReturnCode tsSsn;
+  int fd;
+  struct tcp_info info;
+  socklen_t tcp_info_len = sizeof(info);
+  tsSsn                  = TSHttpTxnClientFdGet(res.txnp, &fd);
+  if (tsSsn != TS_SUCCESS || fd <= 0) {

Review comment:
       Looks good. A minor nit though is to change it to just ```if 
(TSHttpTxnIsInternal(res.txnp)) {``` (== 1 should be implied).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to