Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions plugins/compress/compress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/gold_tests/pluginTest/compress/compress.gold
Original file line number Diff line number Diff line change
Expand Up @@ -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
===
26 changes: 26 additions & 0 deletions tests/gold_tests/pluginTest/compress/compress.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) +
Expand All @@ -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
Expand All @@ -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):

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/gold_tests/pluginTest/compress/compress_userver.gold
Original file line number Diff line number Diff line change
Expand Up @@ -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