Repository: trafficserver Updated Branches: refs/heads/master 2710ad047 -> facce5761
TS-3255: support flush option in gzip plugins Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/facce576 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/facce576 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/facce576 Branch: refs/heads/master Commit: facce57611cd7489ba21a6634adc07ff6e6d4747 Parents: 2710ad0 Author: Chiru Jaladi <[email protected]> Authored: Fri Dec 19 22:26:23 2014 +0000 Committer: Kit Chan <[email protected]> Committed: Fri Dec 19 22:26:23 2014 +0000 ---------------------------------------------------------------------- CHANGES | 2 ++ doc/reference/plugins/gzip.en.rst | 5 +++++ plugins/gzip/configuration.cc | 7 +++++++ plugins/gzip/configuration.h | 4 ++++ plugins/gzip/gzip.cc | 14 ++++++++++++-- 5 files changed, 30 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/facce576/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 57e8e64..f7c4126 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 5.3.0 + *) [TS-3255] support flush option in gzip plugins. + *) [TS-3222] Fix port print to not have leading 0. *) [TS-3088] Enable /etc/hosts resolution. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/facce576/doc/reference/plugins/gzip.en.rst ---------------------------------------------------------------------- diff --git a/doc/reference/plugins/gzip.en.rst b/doc/reference/plugins/gzip.en.rst index 9a08972..2c7e59d 100644 --- a/doc/reference/plugins/gzip.en.rst +++ b/doc/reference/plugins/gzip.en.rst @@ -40,6 +40,7 @@ In this case, the plugin will use the default behaviour: - Don't hide accept encoding from origin servers (for an offloading reverse proxy) - No urls are disallowed from compression +- Disable flush (flush gzipped content to client) Configuration ============= @@ -75,6 +76,8 @@ compressible content types. ``disallow``: Wildcard pattern for disabling compression on urls. +``flush``: (``true`` or ``false``) Enable or disable flushing of gzipped content. + Options can be set globally or on a per-site basis, as such:: # Set some global options first @@ -82,11 +85,13 @@ Options can be set globally or on a per-site basis, as such:: enabled true remove-accept-encoding false compressible-content-type text/* + flush false # Now set a configuration for www.example.com [www.example.com] cache false remove-accept-encoding true disallow /notthis/*.js + flush true See example.gzip.config for example configurations. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/facce576/plugins/gzip/configuration.cc ---------------------------------------------------------------------- diff --git a/plugins/gzip/configuration.cc b/plugins/gzip/configuration.cc index 2ea6472..0b60c62 100644 --- a/plugins/gzip/configuration.cc +++ b/plugins/gzip/configuration.cc @@ -84,6 +84,7 @@ namespace Gzip { kParseEnable, kParseCache, kParseDisallow, + kParseFlush }; void Configuration::AddHostConfiguration(HostConfiguration * hc){ @@ -221,6 +222,8 @@ namespace Gzip { state = kParseCache; } else if (token == "disallow" ) { state = kParseDisallow; + } else if (token == "flush" ) { + state = kParseFlush; } else { warning("failed to interpret \"%s\" at line %zu", token.c_str(), lineno); @@ -246,6 +249,10 @@ namespace Gzip { current_host_configuration->add_disallow(token); state = kParseStart; break; + case kParseFlush: + current_host_configuration->set_flush(token == "true"); + state = kParseStart; + break; } } } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/facce576/plugins/gzip/configuration.h ---------------------------------------------------------------------- diff --git a/plugins/gzip/configuration.h b/plugins/gzip/configuration.h index da11b35..eca1a5b 100644 --- a/plugins/gzip/configuration.h +++ b/plugins/gzip/configuration.h @@ -37,12 +37,15 @@ namespace Gzip { , enabled_(true) , cache_(true) , remove_accept_encoding_(false) + , flush_(false) {} inline bool enabled() { return enabled_; } inline void set_enabled(bool x) { enabled_ = x; } inline bool cache() { return cache_; } inline void set_cache(bool x) { cache_ = x; } + inline bool flush() { return flush_; } + inline void set_flush(bool x) { flush_ = x; } inline bool remove_accept_encoding() { return remove_accept_encoding_; } inline void set_remove_accept_encoding(bool x) { remove_accept_encoding_ = x; } inline std::string host() { return host_; } @@ -56,6 +59,7 @@ namespace Gzip { bool enabled_; bool cache_; bool remove_accept_encoding_; + bool flush_; std::vector<std::string> compressible_content_types_; std::vector<std::string> disallows_; DISALLOW_COPY_AND_ASSIGN(HostConfiguration); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/facce576/plugins/gzip/gzip.cc ---------------------------------------------------------------------- diff --git a/plugins/gzip/gzip.cc b/plugins/gzip/gzip.cc index 2da9a1d..cc43dca 100644 --- a/plugins/gzip/gzip.cc +++ b/plugins/gzip/gzip.cc @@ -259,6 +259,9 @@ gzip_transform_one(GzipData * data, TSIOBufferReader upstream_reader, int amount char *downstream_buffer; int64_t upstream_length, downstream_length; int err; + + TSHttpTxn txnp = (TSHttpTxn) data->txn; + HostConfiguration * hc = (HostConfiguration*)TSHttpTxnArgGet(txnp, arg_idx_host_configuration); while (amount > 0) { downstream_blkp = TSIOBufferReaderStart(upstream_reader); @@ -287,8 +290,14 @@ gzip_transform_one(GzipData * data, TSIOBufferReader upstream_reader, int amount data->zstrm.next_out = (unsigned char *) downstream_buffer; data->zstrm.avail_out = downstream_length; - err = deflate(&data->zstrm, Z_NO_FLUSH); - + if(!hc->flush()) { + debug("gzip_transform: deflate with Z_NO_FLUSH"); + err = deflate(&data->zstrm, Z_NO_FLUSH); + } else { + debug("gzip_transform: deflate with Z_SYNC_FLUSH"); + err = deflate(&data->zstrm, Z_SYNC_FLUSH); + } + if (err != Z_OK) warning("deflate() call failed: %d", err); @@ -420,6 +429,7 @@ gzip_transform_do(TSCont contp) static int gzip_transform(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */) { + if (TSVConnClosedGet(contp)) { gzip_data_destroy((GzipData*)TSContDataGet(contp)); TSContDestroy(contp);
