You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ki...@apache.org on 2021/01/26 17:59:55 UTC

[trafficserver] branch master updated: Enhancements for compress plugin (#7416)

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

kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 714f17b  Enhancements for compress plugin (#7416)
714f17b is described below

commit 714f17b94bed5ac0ef2ca40ce9b77279bff9bbdc
Author: Kit Chan <ki...@apache.org>
AuthorDate: Tue Jan 26 09:59:42 2021 -0800

    Enhancements for compress plugin (#7416)
    
    * Enhancements for compress plugin
    
    * Add a test for POST
---
 plugins/compress/compress.cc                       | 10 +++++++--
 tests/gold_tests/pluginTest/compress/compress.gold |  9 ++++++++
 .../pluginTest/compress/compress.test.py           | 26 ++++++++++++++++++++++
 .../pluginTest/compress/compress_userver.gold      |  1 +
 4 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/plugins/compress/compress.cc b/plugins/compress/compress.cc
index 066bee5..f0b1d8a 100644
--- a/plugins/compress/compress.cc
+++ b/plugins/compress/compress.cc
@@ -66,6 +66,8 @@ const int BROTLI_LGW               = 16;
 
 static const char *global_hidden_header_name = nullptr;
 
+static TSMutex compress_config_mutex = TSMutexCreate();
+
 // Current global configuration, and the previous one (for cleanup)
 Configuration *cur_config  = nullptr;
 Configuration *prev_config = nullptr;
@@ -676,8 +678,9 @@ transformable(TSHttpTxn txnp, bool server, HostConfiguration *host_configuration
   int method_length;
   const char *method = TSHttpHdrMethodGet(cbuf, chdr, &method_length);
 
-  if (!(method_length == TS_HTTP_LEN_GET && memcmp(method, TS_HTTP_METHOD_GET, TS_HTTP_LEN_GET) == 0)) {
-    debug("method is not GET, not compressible");
+  if (!((method_length == TS_HTTP_LEN_GET && memcmp(method, TS_HTTP_METHOD_GET, TS_HTTP_LEN_GET) == 0) ||
+        (method_length == TS_HTTP_LEN_POST && memcmp(method, TS_HTTP_METHOD_POST, TS_HTTP_LEN_POST) == 0))) {
+    debug("method is not GET or POST, not compressible");
     TSHandleMLocRelease(cbuf, TS_NULL_MLOC, chdr);
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     return 0;
@@ -976,11 +979,14 @@ load_global_configuration(TSCont contp)
 
   debug("config swapped, old config %p", oldconfig);
 
+  // need a mutex for when there are multiple reloads going on
+  TSMutexLock(compress_config_mutex);
   if (prev_config) {
     debug("deleting previous configuration container, %p", prev_config);
     delete prev_config;
   }
   prev_config = oldconfig;
+  TSMutexUnlock(compress_config_mutex);
 }
 
 static int
diff --git a/tests/gold_tests/pluginTest/compress/compress.gold b/tests/gold_tests/pluginTest/compress/compress.gold
index 05c8eb5..5067978 100644
--- a/tests/gold_tests/pluginTest/compress/compress.gold
+++ b/tests/gold_tests/pluginTest/compress/compress.gold
@@ -177,3 +177,12 @@
 < Vary: Accept-Encoding
 < Content-Length: 71
 ===
+> POST http://ae-3/obj3 HTTP/1.1
+> X-Ats-Compress-Test: 3/gzip
+> Accept-Encoding: gzip
+< HTTP/1.1 200 OK
+< Content-Type: text/javascript
+< Content-Encoding: gzip
+< Vary: Accept-Encoding
+< Content-Length: 30
+===
diff --git a/tests/gold_tests/pluginTest/compress/compress.test.py b/tests/gold_tests/pluginTest/compress/compress.test.py
index d2daf2a..fdc2097 100644
--- a/tests/gold_tests/pluginTest/compress/compress.test.py
+++ b/tests/gold_tests/pluginTest/compress/compress.test.py
@@ -64,6 +64,14 @@ for i in range(3):
     server.addResponse("sessionfile.log", request_header, response_header)
 
 
+# post for the origin server
+post_request_header = {
+    "headers": "POST /obj3 HTTP/1.1\r\nHost: just.any.thing\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 11\r\n\r\n",
+    "timestamp": "1469733493.993",
+    "body": "knock knock"}
+server.addResponse("sessionfile.log", post_request_header, response_header)
+
+
 def curl(ts, idx, encodingList):
     return (
         "curl --verbose --proxy http://127.0.0.1:{}".format(ts.Variables.port) +
@@ -73,6 +81,15 @@ def curl(ts, idx, encodingList):
     )
 
 
+def curl_post(ts, idx, encodingList):
+    return (
+        "curl --verbose -d 'knock knock' --proxy http://127.0.0.1:{}".format(ts.Variables.port) +
+        " --header 'X-Ats-Compress-Test: {}/{}'".format(idx, encodingList) +
+        " --header 'Accept-Encoding: {0}' 'http://ae-{1}/obj{1}'".format(encodingList, idx) +
+        " 2>> compress_long.log ; printf '\n===\n' >> compress_long.log"
+    )
+
+
 waitForServer = True
 
 waitForTs = True
@@ -99,6 +116,10 @@ ts.Disk.remap_config.AddLine(
     ' @plugin=conf_remap.so @pparam=proxy.config.http.normalize_ae=2' +
     ' @plugin=compress.so @pparam={}/compress2.config'.format(Test.TestDirectory)
 )
+ts.Disk.remap_config.AddLine(
+    'map http://ae-3/ http://127.0.0.1:{}/'.format(server.Variables.Port) +
+    ' @plugin=compress.so @pparam={}/compress.config'.format(Test.TestDirectory)
+)
 
 for i in range(3):
 
@@ -162,6 +183,11 @@ tr = Test.AddTestRun()
 tr.Processes.Default.ReturnCode = 0
 tr.Processes.Default.Command = curl(ts, 0, "aaa, gzip;q=0.666 , ")
 
+# post
+tr = Test.AddTestRun()
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.Command = curl_post(ts, 3, "gzip")
+
 # compress_long.log contains all the output from the curl commands.  The tr removes the carriage returns for easier
 # readability.  Curl seems to have a bug, where it will neglect to output an end of line before outputing an HTTP
 # message header line.  The sed command is a work-around for this problem.  greplog.sh uses the grep command to
diff --git a/tests/gold_tests/pluginTest/compress/compress_userver.gold b/tests/gold_tests/pluginTest/compress/compress_userver.gold
index f3253de..1ddc6a4 100644
--- a/tests/gold_tests/pluginTest/compress/compress_userver.gold
+++ b/tests/gold_tests/pluginTest/compress/compress_userver.gold
@@ -19,3 +19,4 @@
 0/aaa, gzip;q=0.666, bbb
 0/ br ; q=0.666, bbb
 0/aaa, gzip;q=0.666 , 
+3/gzip