diff --git a/plugins/compress/compress.cc b/plugins/compress/compress.cc index b7efe6dba3d..f4fecf146c5 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; @@ -665,8 +667,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); return 0; } @@ -964,11 +967,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 05c8eb579bc..506797893d1 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 d2daf2aa045..fdc2097e07e 100644 --- a/tests/gold_tests/pluginTest/compress/compress.test.py +++ b/tests/gold_tests/pluginTest/compress/compress.test.py @@ -64,6 +64,14 @@ def repeat(str, count): 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 @@ def curl(ts, idx, encodingList): ' @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 @@ def curl(ts, idx, encodingList): 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 f3253deb9a6..1ddc6a4f3b5 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