You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by James Peach <jp...@apache.org> on 2014/10/02 22:09:06 UTC

Re: git commit: TS-3108: Add port matching condition to header_rewrite

On Oct 2, 2014, at 12:47 PM, sorber@apache.org wrote:

> Repository: trafficserver
> Updated Branches:
>  refs/heads/master adae7cd16 -> 5054186f9
> 
> 
> TS-3108: Add port matching condition to header_rewrite
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
> Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/5054186f
> Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/5054186f
> Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/5054186f
> 
> Branch: refs/heads/master
> Commit: 5054186f9083640583d366e732f18f846b65a6c2
> Parents: adae7cd
> Author: Phil Sorber <so...@apache.org>
> Authored: Thu Oct 2 13:47:12 2014 -0600
> Committer: Phil Sorber <so...@apache.org>
> Committed: Thu Oct 2 13:47:12 2014 -0600
> 
> ----------------------------------------------------------------------
> CHANGES                              |  4 +++-
> plugins/header_rewrite/conditions.cc | 29 +++++++++++++++++++++++++++++
> plugins/header_rewrite/conditions.h  | 18 ++++++++++++++++++
> plugins/header_rewrite/factory.cc    |  2 ++
> plugins/header_rewrite/lulu.cc       | 23 +++++++++++++++++++++++
> plugins/header_rewrite/lulu.h        |  2 +-
> 6 files changed, 76 insertions(+), 2 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5054186f/CHANGES
> ----------------------------------------------------------------------
> diff --git a/CHANGES b/CHANGES
> index c21cedc..867e8a3 100644
> --- a/CHANGES
> +++ b/CHANGES
> @@ -1,7 +1,9 @@
>                                                          -*- coding: utf-8 -*-
> Changes with Apache Traffic Server 5.2.0
> 
> -  *) [TS=3068] Remove usage of Boost.
> +  *) [TS-3108] Add port matching condition to header_rewrite.
> +
> +  *) [TS-3068] Remove usage of Boost.
> 
>   *) [TS-2289] Removed old unused AIO modes.
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5054186f/plugins/header_rewrite/conditions.cc
> ----------------------------------------------------------------------
> diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc
> index 0f78ace..be3d28b 100644
> --- a/plugins/header_rewrite/conditions.cc
> +++ b/plugins/header_rewrite/conditions.cc
> @@ -491,3 +491,32 @@ ConditionClientIp::append_value(std::string &s, const Resources &res)
>     s.append(ip);
>   }
> }
> +
> +void
> +ConditionIncomingPort::initialize(Parser &p)
> +{
> +  Condition::initialize(p);
> +
> +  Matchers<uint16_t>* match = new Matchers<uint16_t>(_cond_op);
> +  match->set(static_cast<uint16_t>(strtoul(p.get_arg().c_str(), NULL, 10)));
> +  _matcher = match;
> +}
> +
> +bool
> +ConditionIncomingPort::eval(const Resources &res)
> +{
> +  uint16_t port = getPort(TSHttpTxnIncomingAddrGet(res.txnp));
> +  bool rval = static_cast<const Matchers<uint16_t>*>(_matcher)->test(port);
> +  TSDebug(PLUGIN_NAME, "Evaluating INCOMING-PORT(): %d: rval: %d", port, rval);
> +  return rval;
> +}
> +
> +void
> +ConditionIncomingPort::append_value(std::string &s, const Resources &res)
> +{
> +  std::ostringstream oss;
> +  uint16_t port = getPort(TSHttpTxnIncomingAddrGet(res.txnp));
> +  oss << port;
> +  s += oss.str();
> +  TSDebug(PLUGIN_NAME, "Appending %d to evaluation value -> %s", port, s.c_str());
> +}
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5054186f/plugins/header_rewrite/conditions.h
> ----------------------------------------------------------------------
> diff --git a/plugins/header_rewrite/conditions.h b/plugins/header_rewrite/conditions.h
> index 0b76f42..fbb843d 100644
> --- a/plugins/header_rewrite/conditions.h
> +++ b/plugins/header_rewrite/conditions.h
> @@ -348,4 +348,22 @@ protected:
>   bool eval(const Resources &res);
> };
> 
> +class ConditionIncomingPort : public Condition
> +{
> +public:
> +  ConditionIncomingPort()
> +  {
> +    TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionIncomingPort");
> +  }
> +
> +  void initialize(Parser& p);
> +  void append_value(std::string &s, const Resources &res);
> +
> +protected:
> +  bool eval(const Resources &res);
> +
> +private:
> +  DISALLOW_COPY_AND_ASSIGN(ConditionIncomingPort);
> +};
> +
> #endif // __CONDITIONS_H
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5054186f/plugins/header_rewrite/factory.cc
> ----------------------------------------------------------------------
> diff --git a/plugins/header_rewrite/factory.cc b/plugins/header_rewrite/factory.cc
> index 1d99ea5..eb44369 100644
> --- a/plugins/header_rewrite/factory.cc
> +++ b/plugins/header_rewrite/factory.cc
> @@ -113,6 +113,8 @@ condition_factory(const std::string& cond)
>     c = new ConditionInternalTransaction();
>   } else if (c_name == "CLIENT-IP") {
>     c = new ConditionClientIp();
> +  } else if (c_name == "INCOMING-PORT") {

I think "SERVER-PORT" would be clearer ... also it would not take long to add CLIENT-PORT and SERVER-IP, so make it symmetric :)


J