TS-1443 add enable-gzip option for gzip plugin Author: Conan Wang
Add a configuration option to enable / disable compression for hosts Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/0a51cfb0 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/0a51cfb0 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/0a51cfb0 Branch: refs/heads/master Commit: 0a51cfb0650f9b0a6889f9e95e6b4c1623743bd2 Parents: 150be45 Author: Otto van der Schaaf <[email protected]> Authored: Sat Sep 8 23:20:31 2012 +0200 Committer: Otto van der Schaaf <[email protected]> Committed: Sat Sep 8 23:20:31 2012 +0200 ---------------------------------------------------------------------- plugins/experimental/gzip/README | 4 ++++ plugins/experimental/gzip/configuration.cc | 7 +++++++ plugins/experimental/gzip/configuration.h | 4 ++++ plugins/experimental/gzip/gzip.cc | 8 ++++---- plugins/experimental/gzip/sample.gzip.config | 4 ++++ 5 files changed, 23 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0a51cfb0/plugins/experimental/gzip/README ---------------------------------------------------------------------- diff --git a/plugins/experimental/gzip/README b/plugins/experimental/gzip/README index 07f4155..ff8b807 100644 --- a/plugins/experimental/gzip/README +++ b/plugins/experimental/gzip/README @@ -27,6 +27,8 @@ a sample configuration (sample.gzip.config): ###################################################################### #flags and options are: # +# enable-gzip: default true, set true/false to enable/disable plugin for specific host +# # remove-accept-encoding: this sets if the plugin should hide the accept encoding from origin servers # - to ease the load on the origins # - for when the proxy parses responses, and the resulting compression/decompression @@ -40,6 +42,7 @@ a sample configuration (sample.gzip.config): ###################################################################### #first, we configure the default/global plugin behaviour +enable-gzip true remove-accept-encoding true cache false @@ -52,6 +55,7 @@ disallow */bla* #override the global configuration for a host. #www.foo.nl does NOT inherit anything [www.foo.nl] +enable-gzip true remove-accept-encoding true compressible-content-type text/* http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0a51cfb0/plugins/experimental/gzip/configuration.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/gzip/configuration.cc b/plugins/experimental/gzip/configuration.cc index eb632e8..02d49d0 100644 --- a/plugins/experimental/gzip/configuration.cc +++ b/plugins/experimental/gzip/configuration.cc @@ -81,6 +81,7 @@ namespace Gzip { kParseStart, kParseCompressibleContentType, kParseRemoveAcceptEncoding, + kParseEnable, kParseCache, kParseDisallow, }; @@ -202,6 +203,8 @@ namespace Gzip { state = kParseCompressibleContentType; } else if (token == "remove-accept-encoding" ) { state = kParseRemoveAcceptEncoding; + } else if (token == "enabled" ) { + state = kParseEnable; } else if (token == "cache" ) { state = kParseCache; } else if (token == "disallow" ) { @@ -219,6 +222,10 @@ namespace Gzip { current_host_configuration->set_remove_accept_encoding(token == "true"); state = kParseStart; break; + case kParseEnable: + current_host_configuration->set_enabled(token == "true"); + state = kParseStart; + break; case kParseCache: current_host_configuration->set_cache(token == "true"); state = kParseStart; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0a51cfb0/plugins/experimental/gzip/configuration.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/gzip/configuration.h b/plugins/experimental/gzip/configuration.h index bdcd845..c966678 100644 --- a/plugins/experimental/gzip/configuration.h +++ b/plugins/experimental/gzip/configuration.h @@ -34,10 +34,13 @@ namespace Gzip { public: //todo -> only configuration should be able to construct hostconfig explicit HostConfiguration(std::string host) : host_(host) + , enabled_(true) , cache_(true) , remove_accept_encoding_(false) {} + bool enabled() { return enabled_; } + void set_enabled(bool x) { enabled_ = x; } bool cache() { return cache_; } void set_cache(bool x) { cache_ = x; } bool remove_accept_encoding() { return remove_accept_encoding_; } @@ -50,6 +53,7 @@ namespace Gzip { private: std::string host_; + bool enabled_; bool cache_; bool remove_accept_encoding_; std::vector<std::string> compressible_content_types_; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0a51cfb0/plugins/experimental/gzip/gzip.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/gzip/gzip.cc b/plugins/experimental/gzip/gzip.cc index fe79740..40cbda3 100644 --- a/plugins/experimental/gzip/gzip.cc +++ b/plugins/experimental/gzip/gzip.cc @@ -634,13 +634,13 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) //we could clone the hosting configuration here, to make it deletable on reload? TSHttpTxnArgSet(txnp, arg_idx_host_configuration, (void *) hc); - if (!hc->IsUrlAllowed(url, url_len)) { + if (!hc->enabled() || !hc->IsUrlAllowed(url, url_len)) { //FIXME: no double negatives TSHttpTxnArgSet(txnp, arg_idx_url_disallowed, (void *) &GZIP_ONE); - info("url [%.*s] not compressible", url_len, url); + info("url [%.*s] not allowed", url_len, url); + } else { + normalize_accept_encoding(txnp, req_buf, req_loc); } - - normalize_accept_encoding(txnp, req_buf, req_loc); TSHandleMLocRelease(req_buf, TS_NULL_MLOC, req_loc); } TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0a51cfb0/plugins/experimental/gzip/sample.gzip.config ---------------------------------------------------------------------- diff --git a/plugins/experimental/gzip/sample.gzip.config b/plugins/experimental/gzip/sample.gzip.config index 4938c7b..994d962 100644 --- a/plugins/experimental/gzip/sample.gzip.config +++ b/plugins/experimental/gzip/sample.gzip.config @@ -1,6 +1,8 @@ ###################################################################### #flags and options are: # +# enable-gzip: default true, set true/false to enable/disable plugin for specific host +# # remove-accept-encoding: this sets if the plugin should hide the accept encoding from origin servers # - to ease the load on the origins # - for when the proxy parses responses, and the resulting compression/decompression @@ -14,6 +16,7 @@ ###################################################################### #first, we configure the default/global plugin behaviour +enabled true remove-accept-encoding true cache false @@ -26,6 +29,7 @@ disallow */bla* #override the global configuration for a host. #www.foo.nl does NOT inherit anything [www.foo.nl] +enabled true remove-accept-encoding true compressible-content-type text/*
