You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2018/04/05 19:20:37 UTC
[trafficserver] branch master updated: Adds a 'minimum content
length' setting for gzip plugin
This is an automated email from the ASF dual-hosted git repository.
zwoop 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 6a12bc9 Adds a 'minimum content length' setting for gzip plugin
6a12bc9 is described below
commit 6a12bc90a995f87204f89a8286a2d7860b0c915c
Author: Randall Meyer <ra...@yahoo.com>
AuthorDate: Tue Mar 13 13:14:14 2018 -0700
Adds a 'minimum content length' setting for gzip plugin
Addresses issue #2238
---
plugins/gzip/configuration.cc | 9 ++++++++-
plugins/gzip/configuration.h | 12 ++++++++++++
plugins/gzip/gzip.cc | 15 +++++++++++++++
plugins/gzip/sample.gzip.config | 8 +++++++-
4 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/plugins/gzip/configuration.cc b/plugins/gzip/configuration.cc
index 109ddfa..cbd5792 100644
--- a/plugins/gzip/configuration.cc
+++ b/plugins/gzip/configuration.cc
@@ -104,7 +104,8 @@ enum ParserState {
kParseCache,
kParseDisallow,
kParseFlush,
- kParseAllow
+ kParseAllow,
+ kParseMinimumContentLength
};
void
@@ -377,6 +378,8 @@ Configuration::Parse(const char *path)
} else if (token == "compressible-status-code") {
current_host_configuration->add_compressible_status_codes(line);
state = kParseStart;
+ } else if (token == "minimum-content-length") {
+ state = kParseMinimumContentLength;
} else {
warning("failed to interpret \"%s\" at line %zu", token.c_str(), lineno);
}
@@ -409,6 +412,10 @@ Configuration::Parse(const char *path)
current_host_configuration->add_allow(token);
state = kParseStart;
break;
+ case kParseMinimumContentLength:
+ current_host_configuration->set_minimum_content_length(strtoul(token.c_str(), nullptr, 10));
+ state = kParseStart;
+ break;
}
}
}
diff --git a/plugins/gzip/configuration.h b/plugins/gzip/configuration.h
index 0f671f4..264fb27 100644
--- a/plugins/gzip/configuration.h
+++ b/plugins/gzip/configuration.h
@@ -51,6 +51,7 @@ public:
remove_accept_encoding_(false),
flush_(false),
compression_algorithms_(ALGORITHM_GZIP),
+ minimum_content_length_(1024),
ref_count_(0)
{
}
@@ -111,6 +112,16 @@ public:
{
return !allows_.empty();
}
+ unsigned int
+ minimum_content_length() const
+ {
+ return minimum_content_length_;
+ }
+ void
+ set_minimum_content_length(unsigned int x)
+ {
+ minimum_content_length_ = x;
+ }
void update_defaults();
void add_disallow(const std::string &disallow);
@@ -145,6 +156,7 @@ private:
bool remove_accept_encoding_;
bool flush_;
int compression_algorithms_;
+ unsigned int minimum_content_length_;
int ref_count_;
StringContainer compressible_content_types_;
diff --git a/plugins/gzip/gzip.cc b/plugins/gzip/gzip.cc
index e758973..58ff490 100644
--- a/plugins/gzip/gzip.cc
+++ b/plugins/gzip/gzip.cc
@@ -737,6 +737,21 @@ transformable(TSHttpTxn txnp, bool server, HostConfiguration *host_configuration
return 0;
}
+ field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_CONTENT_LENGTH, TS_MIME_LEN_CONTENT_LENGTH);
+ if (field_loc != TS_NULL_MLOC) {
+ unsigned int value = TSMimeHdrFieldValueUintGet(bufp, hdr_loc, field_loc, -1);
+ TSHandleMLocRelease(bufp, hdr_loc, field_loc);
+ if (value == 0) {
+ info("response is 0-length, not compressible");
+ return 0;
+ }
+
+ if (value < host_configuration->minimum_content_length()) {
+ info("response is is smaller than minimum content length, not compressing");
+ return 0;
+ }
+ }
+
/* We only want to do gzip compression on documents that have a
content type of "text/" or "application/x-javascript". */
field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_CONTENT_TYPE, -1);
diff --git a/plugins/gzip/sample.gzip.config b/plugins/gzip/sample.gzip.config
index 11309bd..d8ff721 100644
--- a/plugins/gzip/sample.gzip.config
+++ b/plugins/gzip/sample.gzip.config
@@ -29,10 +29,13 @@
#
# compressible-content-type: wildcard pattern for matching compressible content types
#
-# disallow: wildcard pattern for disablign compression on urls
+# disallow: wildcard pattern for disabling compression on urls
#
# compressible-status-code: a comma separated list of status codes in which to enable compression
#
+# minimum-content-length: minimum content length for compression to be enabled (in bytes)
+# - this setting only applies if the origin response has a Content-Length header
+#
######################################################################
#first, we configure the default/global plugin behaviour
@@ -47,6 +50,8 @@ disallow /notthis/*.js
disallow /notthat*
disallow */bla*
+minimum-content-length 1024
+
#override the global configuration for a host.
#www.foo.nl does NOT inherit anything
[www.foo.nl]
@@ -57,6 +62,7 @@ compressible-content-type text/*
compressible-content-type !text/javascript
compressible-status-code 200,206,409
+minimum-content-length 1024
cache false
disallow /notthis/*.js
--
To stop receiving notification emails like this one, please contact
zwoop@apache.org.