You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by so...@apache.org on 2016/04/21 19:18:03 UTC

[trafficserver] branch 6.2.x updated (d9b5237 -> 12084df)

This is an automated email from the ASF dual-hosted git repository.

sorber pushed a change to branch 6.2.x
in repository https://git-dual.apache.org/repos/asf/trafficserver.git.

      from  d9b5237   Mark proxy.config.ssl.SSLv2 and proxy.config.ssl.SSLv3 as deprecated in the docs.
       new  bad058e   TS-4318 Fix a regression in regex rules
       new  8261836   TS-4147 Allow gzip plugin to be a remap plugin
       new  12084df   TS-4361: Remove TS_FETCH_EVENT handlers from Http2ClientSession. This closes #581.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.


Summary of changes:
 doc/admin-guide/plugins/gzip.en.rst         |   9 +-
 plugins/experimental/geoip_acl/acl.cc       |  25 +--
 plugins/experimental/geoip_acl/acl.h        |   8 +-
 plugins/experimental/geoip_acl/geoip_acl.cc |   1 +
 plugins/gzip/gzip.cc                        | 159 ++++++++++++++----
 plugins/gzip/tests/test_gzip.py             | 241 ++++++++++++++++++++++++++++
 proxy/http2/Http2ClientSession.cc           |   7 -
 7 files changed, 397 insertions(+), 53 deletions(-)
 create mode 100644 plugins/gzip/tests/test_gzip.py

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].

[trafficserver] 03/03: TS-4361: Remove TS_FETCH_EVENT handlers from Http2ClientSession. This closes #581.

Posted by so...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sorber pushed a commit to branch 6.2.x
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 12084df688483d939654dd53d3c82e5f3ccaaaa9
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Mon Apr 18 15:16:56 2016 +0900

    TS-4361: Remove TS_FETCH_EVENT handlers from Http2ClientSession. This closes #581.
    
    (cherry picked from commit 3872a385cac3d43de25bdaf38c56bbcc2cb6f65b)
---
 proxy/http2/Http2ClientSession.cc | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/proxy/http2/Http2ClientSession.cc b/proxy/http2/Http2ClientSession.cc
index 8b8427e..d759c84 100644
--- a/proxy/http2/Http2ClientSession.cc
+++ b/proxy/http2/Http2ClientSession.cc
@@ -287,13 +287,6 @@ Http2ClientSession::main_event_handler(int event, void *edata)
     }
     return 0;
 
-  case TS_FETCH_EVENT_EXT_HEAD_DONE:
-  case TS_FETCH_EVENT_EXT_BODY_READY:
-  case TS_FETCH_EVENT_EXT_BODY_DONE:
-    // Process responses from origin server
-    send_connection_event(&this->connection_state, event, edata);
-    return 0;
-
   default:
     DebugHttp2Ssn("unexpected event=%d edata=%p", event, edata);
     ink_release_assert(0);

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.

[trafficserver] 01/03: TS-4318 Fix a regression in regex rules

Posted by so...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sorber pushed a commit to branch 6.2.x
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit bad058eb152772f1df0fe4c133f4ac62fa0eaa12
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Mon Apr 4 15:06:47 2016 -0600

    TS-4318 Fix a regression in regex rules
    
    The refactoring done earlier broke the config loading of rules using
    the regular expressions. This restore that functionality, but cleaner.
    
    (cherry picked from commit 431a8f838e75338cb685b95c213a6140f5cbdcc7)
---
 plugins/experimental/geoip_acl/acl.cc       | 25 ++++++++++++++++---------
 plugins/experimental/geoip_acl/acl.h        |  8 +++++---
 plugins/experimental/geoip_acl/geoip_acl.cc |  1 +
 3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/plugins/experimental/geoip_acl/acl.cc b/plugins/experimental/geoip_acl/acl.cc
index 9b30679..e5e09ff 100644
--- a/plugins/experimental/geoip_acl/acl.cc
+++ b/plugins/experimental/geoip_acl/acl.cc
@@ -120,7 +120,7 @@ Acl::read_html(const char *fn)
 
 // Implementations for the RegexAcl class
 bool
-RegexAcl::parse_line(const char *filename, const std::string &line, int lineno)
+RegexAcl::parse_line(const char *filename, const std::string &line, int lineno, int &tokens)
 {
   static const char _SEPARATOR[] = " \t\n";
   std::string regex, tmp;
@@ -155,6 +155,7 @@ RegexAcl::parse_line(const char *filename, const std::string &line, int lineno)
           pos2 = line.find_first_of(_SEPARATOR, pos1);
           tmp = line.substr(pos1, pos2 - pos1);
           _acl->add_token(tmp);
+          ++tokens;
         }
         compile(regex, filename, lineno);
         TSDebug(PLUGIN_NAME, "Added regex rule for /%s/", regex.c_str());
@@ -220,7 +221,7 @@ CountryAcl::add_token(const std::string &str)
 }
 
 void
-CountryAcl::read_regex(const char *fn)
+CountryAcl::read_regex(const char *fn, int &tokens)
 {
   std::ifstream f;
   int lineno = 0;
@@ -234,7 +235,7 @@ CountryAcl::read_regex(const char *fn)
       getline(f, line);
       ++lineno;
       acl = new RegexAcl(new CountryAcl());
-      if (acl->parse_line(fn, line, lineno)) {
+      if (acl->parse_line(fn, line, lineno, tokens)) {
         if (NULL == _regexes) {
           _regexes = acl;
         } else {
@@ -255,6 +256,9 @@ CountryAcl::read_regex(const char *fn)
 bool
 CountryAcl::eval(TSRemapRequestInfo *rri, TSHttpTxn txnp) const
 {
+  bool ret = _allow;
+
+  TSDebug(PLUGIN_NAME, "CountryAcl::eval() called, default ACL is %s", ret ? "allow" : "deny");
   // If there are regex rules, they take priority first. If a regex matches, we will
   // honor it's eval() rule. If no regexes matches, fall back on the default (which is
   // "allow" if nothing else is specified).
@@ -269,16 +273,19 @@ CountryAcl::eval(TSRemapRequestInfo *rri, TSHttpTxn txnp) const
         return acl->eval(rri, txnp);
       }
     } while ((acl = acl->next()));
+    ret = !_allow; // Now we invert the default since no regexes matched
   }
 
   // None of the regexes (if any) matched, so fallback to the remap defaults if there are any.
   int iso = country_id_by_addr(TSHttpTxnClientAddrGet(txnp));
 
-  if ((iso <= 0) || (!_iso_country_codes[iso])) {
-    return !_allow;
+  if ((iso <= 0) || !_iso_country_codes[iso]) {
+    TSDebug(PLUGIN_NAME, "ISO not found in table, returning %d", !ret);
+    return !ret;
   }
 
-  return _allow;
+  TSDebug(PLUGIN_NAME, "ISO was found in table, or -1, returning %d", ret);
+  return ret;
 }
 
 int
@@ -288,11 +295,11 @@ CountryAcl::process_args(int argc, char *argv[])
 
   for (int i = 3; i < argc; ++i) {
     if (!strncmp(argv[i], "allow", 5)) {
-      _allow = true;
+      set_allow(true);
     } else if (!strncmp(argv[i], "deny", 4)) {
-      _allow = false;
+      set_allow(false);
     } else if (!strncmp(argv[i], "regex::", 7)) {
-      read_regex(argv[i] + 7);
+      read_regex(argv[i] + 7, tokens);
     } else if (!strncmp(argv[i], "html::", 6)) {
       read_html(argv[i] + 6);
     } else { // ISO codes assumed for the rest
diff --git a/plugins/experimental/geoip_acl/acl.h b/plugins/experimental/geoip_acl/acl.h
index 5067a75..45bd500 100644
--- a/plugins/experimental/geoip_acl/acl.h
+++ b/plugins/experimental/geoip_acl/acl.h
@@ -51,7 +51,7 @@ public:
   Acl() : _allow(true), _added_tokens(0) {}
   virtual ~Acl() {}
   // These have to be implemented for each ACL type
-  virtual void read_regex(const char *fn) = 0;
+  virtual void read_regex(const char *fn, int &tokens) = 0;
   virtual int process_args(int argc, char *argv[]) = 0;
   virtual bool eval(TSRemapRequestInfo *rri, TSHttpTxn txnp) const = 0;
   virtual void add_token(const std::string &str) = 0;
@@ -83,6 +83,8 @@ protected:
   std::string _html;
   bool _allow;
   int _added_tokens;
+
+  // Class members
   static GeoDBHandle _geoip;
   static GeoDBHandle _geoip6;
 };
@@ -119,7 +121,7 @@ public:
   }
 
   void append(RegexAcl *ra);
-  bool parse_line(const char *filename, const std::string &line, int lineno);
+  bool parse_line(const char *filename, const std::string &line, int lineno, int &tokens);
 
 private:
   bool compile(const std::string &str, const char *filename, int lineno);
@@ -135,7 +137,7 @@ class CountryAcl : public Acl
 {
 public:
   CountryAcl() : _regexes(NULL) { memset(_iso_country_codes, 0, sizeof(_iso_country_codes)); }
-  void read_regex(const char *fn);
+  void read_regex(const char *fn, int &tokens);
   int process_args(int argc, char *argv[]);
   bool eval(TSRemapRequestInfo *rri, TSHttpTxn txnp) const;
   void add_token(const std::string &str);
diff --git a/plugins/experimental/geoip_acl/geoip_acl.cc b/plugins/experimental/geoip_acl/geoip_acl.cc
index 63072b0..1e5788e 100644
--- a/plugins/experimental/geoip_acl/geoip_acl.cc
+++ b/plugins/experimental/geoip_acl/geoip_acl.cc
@@ -105,6 +105,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
     Acl *a = static_cast<Acl *>(ih);
 
     if (!a->eval(rri, rh)) {
+      TSDebug(PLUGIN_NAME, "denying request");
       TSHttpTxnSetHttpRetStatus((TSHttpTxn)rh, (TSHttpStatus)403);
       a->send_html((TSHttpTxn)rh);
     }

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.

[trafficserver] 02/03: TS-4147 Allow gzip plugin to be a remap plugin

Posted by so...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sorber pushed a commit to branch 6.2.x
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 8261836994bc74fd3f1a078c976082e91b4bc976
Author: Meera Mosale Nataraja <me...@gmail.com>
AuthorDate: Mon Apr 18 12:51:03 2016 -0700

    TS-4147 Allow gzip plugin to be a remap plugin
    
    (cherry picked from commit 3d7cdbfa1dc52e81c2698dfbac526dec1d336246)
---
 doc/admin-guide/plugins/gzip.en.rst |   9 +-
 plugins/gzip/gzip.cc                | 159 +++++++++++++++++++-----
 plugins/gzip/tests/test_gzip.py     | 241 ++++++++++++++++++++++++++++++++++++
 3 files changed, 375 insertions(+), 34 deletions(-)

diff --git a/doc/admin-guide/plugins/gzip.en.rst b/doc/admin-guide/plugins/gzip.en.rst
index 51a55f3..bf84a18 100644
--- a/doc/admin-guide/plugins/gzip.en.rst
+++ b/doc/admin-guide/plugins/gzip.en.rst
@@ -56,7 +56,8 @@ are no special steps necessary for its installation.
 Configuration
 =============
 
-This plugin is enabled globally for |TS| by adding the following to your
+This plugin can be used as either global plugin or remap plugin.
+It can be enabled globally for |TS| by adding the following to your
 :file:`plugin.config`::
 
     gzip.so
@@ -80,11 +81,17 @@ configuration provided with the plugin's source)::
 
     gzip.so <path-to-plugin>/sample.gzip.config
 
+This can be used as remap plugin by pointing to config file in remap rule 
+:file:`remap.config`::
+    @plugin=gzip.so @pparam=--config=<path-to-plugin>/sample.gzip.config 
+
 The following sections detail the options you may specify in the plugin's
 configuration file. Options may be used globally, or may be specified on a
 per-site basis by preceding them with a `[<site>]` line, where `<site>` is the
 client-facing domain for which the options should apply.
 
+Per site configuration for remap plugin should be ignored.
+
 cache
 -----
 
diff --git a/plugins/gzip/gzip.cc b/plugins/gzip/gzip.cc
index 8c978b7..10970c8 100644
--- a/plugins/gzip/gzip.cc
+++ b/plugins/gzip/gzip.cc
@@ -30,6 +30,7 @@
 #include "debug_macros.h"
 #include "misc.h"
 #include "configuration.h"
+#include "ts/remap.h"
 
 using namespace std;
 using namespace Gzip;
@@ -594,18 +595,23 @@ gzip_transform_add(TSHttpTxn txnp, HostConfiguration *hc, int compress_type)
 }
 
 HostConfiguration *
-find_host_configuration(TSHttpTxn /* txnp ATS_UNUSED */, TSMBuffer bufp, TSMLoc locp)
+find_host_configuration(TSHttpTxn /* txnp ATS_UNUSED */, TSMBuffer bufp, TSMLoc locp, Configuration *config)
 {
   TSMLoc fieldp = TSMimeHdrFieldFind(bufp, locp, TS_MIME_FIELD_HOST, TS_MIME_LEN_HOST);
   int strl = 0;
   const char *strv = NULL;
+  HostConfiguration *host_configuration;
 
   if (fieldp) {
     strv = TSMimeHdrFieldValueStringGet(bufp, locp, fieldp, -1, &strl);
     TSHandleMLocRelease(bufp, locp, fieldp);
   }
-
-  return cur_config->find(strv, strl);
+  if (config == NULL) {
+    host_configuration = cur_config->find(strv, strl);
+  } else {
+    host_configuration = config->find(strv, strl);
+  }
+  return host_configuration;
 }
 
 static int
@@ -685,45 +691,67 @@ transform_plugin(TSCont contp, TSEvent event, void *edata)
   return 0;
 }
 
-static int
-transform_global_plugin(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata)
+/**
+ * This handles gzip request
+ * 1. Reads the client request header
+ * 2. For global plugin, get host configuration from global config
+ *    For remap plugin, get host configuration from configs populated through remap
+ * 3. Check for Accept encoding
+ * 4. Schedules TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK and TS_HTTP_TXN_CLOSE_HOOK for
+ *    further processing
+ */
+static void
+handle_gzip_request(TSHttpTxn txnp, Configuration *config)
 {
-  TSHttpTxn txnp = (TSHttpTxn)edata;
   TSMBuffer req_buf;
   TSMLoc req_loc;
+  HostConfiguration *hc;
 
-  switch (event) {
-  case TS_EVENT_HTTP_READ_REQUEST_HDR:
-    if (TSHttpTxnClientReqGet(txnp, &req_buf, &req_loc) == TS_SUCCESS) {
-      HostConfiguration *hc = find_host_configuration(txnp, req_buf, req_loc); // Get a lease on the
-      bool allowed = false;
-
-      if (hc->enabled()) {
-        if (hc->has_disallows()) {
-          int url_len;
-          char *url = TSHttpTxnEffectiveUrlStringGet(txnp, &url_len);
-
-          allowed = hc->is_url_allowed(url, url_len);
-          TSfree(url);
-        } else {
-          allowed = true;
-        }
-      }
-
-      if (allowed) {
-        TSCont transform_contp = TSContCreate(transform_plugin, NULL);
+  if (TSHttpTxnClientReqGet(txnp, &req_buf, &req_loc) == TS_SUCCESS) {
+    if (config == NULL) {
+      hc = find_host_configuration(txnp, req_buf, req_loc, NULL); // Get a lease on the global config
+    } else {
+      hc = find_host_configuration(txnp, req_buf, req_loc, config); // Get a lease on the local config passed through doRemap
+    }
+    bool allowed = false;
 
-        info("Kicking off gzip plugin for request");
+    if (hc->enabled()) {
+      if (hc->has_disallows()) {
+        int url_len;
+        char *url = TSHttpTxnEffectiveUrlStringGet(txnp, &url_len);
 
-        TSContDataSet(transform_contp, (void *)hc);
-        normalize_accept_encoding(txnp, req_buf, req_loc);
-        TSHttpTxnHookAdd(txnp, TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, transform_contp);
-        TSHttpTxnHookAdd(txnp, TS_HTTP_TXN_CLOSE_HOOK, transform_contp); // To release the config
+        allowed = hc->is_url_allowed(url, url_len);
+        TSfree(url);
       } else {
-        hc->release(); // No longer need this configuration, release it.
+        allowed = true;
       }
-      TSHandleMLocRelease(req_buf, TS_NULL_MLOC, req_loc);
     }
+
+    if (allowed) {
+      TSCont transform_contp = TSContCreate(transform_plugin, NULL);
+
+      TSContDataSet(transform_contp, (void *)hc);
+
+      info("Kicking off gzip plugin for request");
+      normalize_accept_encoding(txnp, req_buf, req_loc);
+      TSHttpTxnHookAdd(txnp, TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, transform_contp);
+      TSHttpTxnHookAdd(txnp, TS_HTTP_TXN_CLOSE_HOOK, transform_contp); // To release the config
+    } else {
+      hc->release(); // No longer need this configuration, release it.
+    }
+    TSHandleMLocRelease(req_buf, TS_NULL_MLOC, req_loc);
+  }
+}
+
+static int
+transform_global_plugin(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata)
+{
+  TSHttpTxn txnp = (TSHttpTxn)edata;
+
+  switch (event) {
+  case TS_EVENT_HTTP_READ_REQUEST_HDR:
+    // Handle gzip request and use the global configs
+    handle_gzip_request(txnp, NULL);
     break;
 
   default:
@@ -796,3 +824,68 @@ TSPluginInit(int argc, const char *argv[])
   TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, transform_global_contp);
   info("loaded");
 }
+
+//////////////////////////////////////////////////////////////////////////////
+// Initialize the plugin as a remap plugin.
+//
+TSReturnCode
+TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
+{
+  if (!api_info) {
+    strncpy(errbuf, "[tsremap_init] - Invalid TSRemapInterface argument", errbuf_size - 1);
+    return TS_ERROR;
+  }
+
+  if (api_info->tsremap_version < TSREMAP_VERSION) {
+    snprintf(errbuf, errbuf_size - 1, "[TSRemapInit] - Incorrect API version %ld.%ld", api_info->tsremap_version >> 16,
+             (api_info->tsremap_version & 0xffff));
+    return TS_ERROR;
+  }
+
+  info("The gzip plugin is successfully initialized");
+  return TS_SUCCESS;
+}
+
+TSReturnCode
+TSRemapNewInstance(int argc, char *argv[], void **instance, char *errbuf, int errbuf_size)
+{
+  info("Instantiating a new gzip plugin remap rule");
+  info("Reading gzip config from file = %s", argv[2]);
+
+  const char *config_path = NULL;
+
+  if (argc > 4) {
+    fatal("The gzip plugin does not accept more than one plugin argument");
+  } else if (argc == 3) {
+    config_path = TSstrdup(argv[2]);
+  }
+  global_hidden_header_name = init_hidden_header_name();
+
+  Configuration *config = Configuration::Parse(config_path);
+  *instance = config;
+
+  free((void *)config_path);
+  info("Configuration loaded");
+  return TS_SUCCESS;
+}
+
+void
+TSRemapDeleteInstance(void *instance)
+{
+  debug("Cleanup configs read from remap");
+  static_cast<Configuration *>(instance)->release_all();
+}
+
+TSRemapStatus
+TSRemapDoRemap(void *instance, TSHttpTxn txnp, TSRemapRequestInfo *rri)
+{
+  if (NULL == instance) {
+    info("No Rules configured, falling back to default");
+  } else {
+    info("Remap Rules configured for gzip");
+    Configuration *config = (Configuration *)instance;
+    // Handle gzip request and use the configs populated from remap instance
+    handle_gzip_request(txnp, config);
+  }
+  return TSREMAP_NO_REMAP;
+}
diff --git a/plugins/gzip/tests/test_gzip.py b/plugins/gzip/tests/test_gzip.py
new file mode 100644
index 0000000..137f271
--- /dev/null
+++ b/plugins/gzip/tests/test_gzip.py
@@ -0,0 +1,241 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+import requests
+import logging
+import random, string
+
+import tsqa.test_cases
+import tsqa.utils
+import tsqa.endpoint
+import os
+
+origin_content_length = 0
+log = logging.getLogger(__name__)
+
+#Test positive cases of remap gzip plugin
+gzip_remap_bench = [
+             # Test gzip
+            { "args": "@pparam=gzip1.config",
+              "files": [("gzip1.config", "enabled true\nremove-accept-encoding true\ncache false\ncompressible-content-type text/*\n")
+                       ],
+            },
+            { "args": "@pparam=gzip2.config",
+              "files": [("gzip2.config", "enabled true\nremove-accept-encoding false\ncache false\ncompressible-content-type text/*\n")
+                       ],
+            },
+            { "args": "@pparam=gzip3.config",
+              "files": [("gzip3.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\n")
+                       ],
+            },
+            { "args": "@pparam=gzip4.config",
+              "files": [("gzip4.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\nflush true\n")
+                       ],
+            },
+            { "args": "@pparam=gzip5.config",
+              "files": [("gzip5.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\nflush false\n")
+                       ],
+            },
+            ]
+
+#Test negative cases of remap gzip plugin
+gzip_remap_negative_bench =  [
+            #Test when gzip is disabled
+            { "args": "@pparam=gzip_negative1.config",
+              "files": [("gzip_negative1.config", "enabled false\nremove-accept-encoding true\ncache false\ncompressible-content-type text/*\n")
+                        ],
+            },
+            #Test when compressible content doesn't match
+            { "args": "@pparam=gzip_negative2.config",
+              "files": [("gzip_negative2.config", "enabled true\nremove-accept-encoding true\ncache false\ncompressible-content-type !text/*\n")
+                        ],
+            },
+            #Test when disallow is configured to match some pattern
+            { "args": "@pparam=gzip_negative3.config",
+              "files": [("gzip_negative3.config", "enabled true\nremove-accept-encoding true\ncache false\ncompressible-content-type text/*\ndisallow *test*\n")
+                        ],
+            },
+            ]
+
+#Test global gzip plugin
+gzip_global_bench = [
+            { "args": "gzip_global1.config",
+              "files": [("gzip_global1.config", "enabled true\nremove-accept-encoding true\ncache true\ncompressible-content-type text/*\n")
+                       ],
+            },
+            ]
+
+#Set up an origin server which returns random string.
+def handler(request):
+    global origin_content_length
+    rand_string = ''.join(random.choice(string.lowercase) for i in range(500))
+    origin_content_length = len(rand_string)
+    return rand_string
+
+def create_config_files(env, test):
+    # Create gzip config files.
+    for file in test['files']:
+        filename = file[0]
+        content = file[1]
+        path = os.path.join(env.layout.prefix, 'etc/trafficserver', filename);
+        with open(path, 'w') as fh:
+            fh.write(content)
+
+class StaticEnvironmentCase(tsqa.test_cases.EnvironmentCase):
+    @classmethod
+    def getEnv(cls):
+        #layout = tsqa.environment.Layout('/opt/gitlab-gzip')
+        layout = tsqa.environment.Layout('/opt/apache/trafficserver.TS-4147')
+        env = tsqa.environment.Environment()
+        env.clone(layout=layout)
+        return env
+
+#Test gzip remap plugin
+class TestGzipRemapPlugin(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCase):
+    @classmethod
+    def setUpEnv(cls, env):
+        cls.configs['plugin.config'].add_line('xdebug.so')
+        cls.configs['records.config']['CONFIG'].update({
+           'proxy.config.diags.debug.enabled': 1,
+           'proxy.config.diags.debug.tags': '.*',
+           'proxy.config.diags.debug.tags': 'gzip.*',
+           'proxy.config.url_remap.pristine_host_hdr': 1,})
+
+        cls.http_endpoint.add_handler('/path/to/object', handler)
+
+        def add_remap_rule(remap_prefix, remap_index, test):
+            host = 'test_{0}_{1}.example.com'.format(remap_prefix, remap_index)
+            port = cls.configs['records.config']['CONFIG']['proxy.config.http.server_ports']
+            args = test['args']
+            remap_rule = 'map http://{0}:{1} http://127.0.0.1:{2} @plugin=gzip.so {3}'.format(host, port, cls.http_endpoint.address[1], args)
+            log.info('  {0}'.format(remap_rule))
+            cls.configs['remap.config'].add_line(remap_rule)
+
+        # Prepare gzip tests related remap rules.
+        i = 0
+        for test in gzip_remap_bench:
+            add_remap_rule("gzip", i, test)
+            create_config_files(env, test)
+            i+=1
+
+        #Prepare negative gzip tests related remap rules.
+        i = 0
+        for test in gzip_remap_negative_bench:
+            add_remap_rule("gzip_negative", i, test)
+            create_config_files(env, test)
+            i+=1
+
+    def send_request(self,remap_prefix, remap_index):
+        host = 'test_{0}_{1}.example.com'.format( remap_prefix, remap_index)
+        port = self.configs['records.config']['CONFIG']['proxy.config.http.server_ports']
+        url = 'http://127.0.0.1:{0}/path/to/object'.format(port)
+        log.info('host is {0}, port is {1}, url is {2}'.format(host, port, url))
+        s = requests.Session()
+        s.headers.update({'Host': '{0}:{1}'.format(host, port)})
+        s.headers.update({'Accept-Encoding:': 'gzip'})
+        response = s.get(url)
+        log.info('Response headers obtained: {0}'.format(response.headers))
+        return response
+
+    def send_gzip_request(self, remap_prefix, remap_index):
+        '''
+        Sends a gzip request to the traffic server
+        '''
+        response = self.send_request(remap_prefix, remap_index)
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(response.headers['Content-Encoding'], 'gzip')
+        self.assertLess(int(response.headers['Content-Length']), int(origin_content_length))
+
+    def send_gzip_request_negative(self, remap_prefix, remap_index):
+        '''
+        Sends a gzip request to the traffic server
+        '''
+        response = self.send_request(remap_prefix, remap_index)
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(int(response.headers['Content-Length']), int(origin_content_length))
+
+    def test_gzip_remap_plugin(self):
+        i = 0
+        for test in gzip_remap_bench:
+            self.send_gzip_request('gzip', i)
+            i += 1
+
+        i = 0
+        for test in gzip_remap_negative_bench:
+            self.send_gzip_request_negative('gzip_negative', i)
+            i += 1
+
+#Test gzip global plugin
+class TestGzipGlobalPlugin(tsqa.test_cases.DynamicHTTPEndpointCase, StaticEnvironmentCase):
+    @classmethod
+    def setUpEnv(cls, env):
+        cls.configs['plugin.config'].add_line('xdebug.so')
+
+        cls.configs['records.config']['CONFIG'].update({
+           'proxy.config.diags.debug.enabled': 1,
+           'proxy.config.diags.debug.tags': 'gzip.*',
+           'proxy.config.url_remap.pristine_host_hdr': 1,})
+
+        cls.http_endpoint.add_handler('/path/to/object', handler)
+
+        def add_remap_rule(remap_prefix, remap_index):
+            host = 'test_{0}_{1}.example.com'.format(remap_prefix, remap_index)
+            port = cls.configs['records.config']['CONFIG']['proxy.config.http.server_ports']
+            remap_rule = 'map http://{0}:{1} http://127.0.0.1:{2}'.format(host, port, cls.http_endpoint.address[1])
+            log.info('  {0}'.format(remap_rule))
+            cls.configs['remap.config'].add_line(remap_rule)
+
+        def add_global_plugin_rule(test):
+            args = test['args']
+            plugin_rule = 'gzip.so {0}'.format(args)
+            log.info('  {0}'.format(plugin_rule))
+            cls.configs['plugin.config'].add_line(plugin_rule)
+
+        # Prepare gzip plugin rules
+        i = 0
+        for test in gzip_global_bench:
+            add_remap_rule("gzip_global",i)
+            add_global_plugin_rule(test)
+            create_config_files(env, test)
+            i+=1
+
+    def send_request(self,remap_prefix, remap_index):
+        host = 'test_{0}_{1}.example.com'.format( remap_prefix, remap_index)
+        port = self.configs['records.config']['CONFIG']['proxy.config.http.server_ports']
+        url = 'http://127.0.0.1:{0}/path/to/object'.format(port)
+        log.info('host is {0}, port is {1}, url is {2}'.format(host, port, url))
+        s = requests.Session()
+        s.headers.update({'Host': '{0}:{1}'.format(host, port)})
+        s.headers.update({'Accept-Encoding:': 'gzip'})
+        response = s.get(url)
+        log.info('Response headers obtained: {0}'.format(response.headers))
+        return response
+
+    def send_global_gzip_request(self, remap_prefix, remap_index):
+        '''
+        Sends a gzip request to the traffic server
+        '''
+        response = self.send_request(remap_prefix, remap_index)
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(response.headers['Content-Encoding'], 'gzip')
+        self.assertLess(int(response.headers['Content-Length']), int(origin_content_length))
+
+    def test_gzip_global_plugin(self):
+        i = 0
+        for test in gzip_global_bench:
+            self.send_global_gzip_request("gzip_global", i)
+            i += 1
+

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.