This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 1b37031  option to disable compression for range request's response 
(#7287)
1b37031 is described below

commit 1b37031319cc04ca0b1c8c5a9a09bfc74e32a8f5
Author: Vijay Mamidi <vijayabhaskar_mam...@yahoo.com>
AuthorDate: Wed Jan 20 08:45:49 2021 -0800

    option to disable compression for range request's response (#7287)
    
    * option to disable compression for range request's response
    
    * option to disable compression for range request's response
    
    (cherry picked from commit 34ead16508ce01eec6a80e44d7dd52cce64b39ff)
---
 doc/admin-guide/plugins/compress.en.rst |  6 ++++++
 plugins/compress/compress.cc            | 14 +++++++++++++-
 plugins/compress/configuration.cc       |  7 +++++++
 plugins/compress/configuration.h        | 12 ++++++++++++
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/doc/admin-guide/plugins/compress.en.rst 
b/doc/admin-guide/plugins/compress.en.rst
index 41cf6a6..f58454e 100644
--- a/doc/admin-guide/plugins/compress.en.rst
+++ b/doc/admin-guide/plugins/compress.en.rst
@@ -103,6 +103,12 @@ versions of the content as :term:`alternates <alternate>`. 
When set to
 ``false``, |TS| will cache only the compressed or decompressed variant returned
 by the origin. Enabled by default.
 
+range-request
+-----
+
+When set to ``true``, causes |TS| to compress responses to Range Requests.
+Disabled by default. Setting this to true while setting cache to false leads 
to delivering corrupted content.
+
 compressible-content-type
 -------------------------
 
diff --git a/plugins/compress/compress.cc b/plugins/compress/compress.cc
index b7efe6d..066bee5 100644
--- a/plugins/compress/compress.cc
+++ b/plugins/compress/compress.cc
@@ -629,7 +629,7 @@ transformable(TSHttpTxn txnp, bool server, 
HostConfiguration *host_configuration
   /* Client request header */
   TSMBuffer cbuf;
   TSMLoc chdr;
-  TSMLoc cfield;
+  TSMLoc cfield, rfield;
 
   const char *value;
   int len;
@@ -661,6 +661,17 @@ transformable(TSHttpTxn txnp, bool server, 
HostConfiguration *host_configuration
     return 0;
   }
 
+  // check if Range Requests are cacheable
+  bool range_request = host_configuration->range_request();
+  rfield             = TSMimeHdrFieldFind(cbuf, chdr, TS_MIME_FIELD_RANGE, 
TS_MIME_LEN_RANGE);
+  if (rfield != TS_NULL_MLOC && !range_request) {
+    debug("Range header found in the request and range_request is configured 
as false, not compressible");
+    TSHandleMLocRelease(cbuf, chdr, rfield);
+    TSHandleMLocRelease(cbuf, TS_NULL_MLOC, chdr);
+    TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
+    return 0;
+  }
+
   // the only compressible method is currently GET.
   int method_length;
   const char *method = TSHttpHdrMethodGet(cbuf, chdr, &method_length);
@@ -668,6 +679,7 @@ transformable(TSHttpTxn txnp, bool server, 
HostConfiguration *host_configuration
   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");
     TSHandleMLocRelease(cbuf, TS_NULL_MLOC, chdr);
+    TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     return 0;
   }
 
diff --git a/plugins/compress/configuration.cc 
b/plugins/compress/configuration.cc
index b6211a4..f582b71 100644
--- a/plugins/compress/configuration.cc
+++ b/plugins/compress/configuration.cc
@@ -105,6 +105,7 @@ enum ParserState {
   kParseRemoveAcceptEncoding,
   kParseEnable,
   kParseCache,
+  kParseRangeRequest,
   kParseFlush,
   kParseAllow,
   kParseMinimumContentLength
@@ -347,6 +348,8 @@ Configuration::Parse(const char *path)
           state = kParseEnable;
         } else if (token == "cache") {
           state = kParseCache;
+        } else if (token == "range-request") {
+          state = kParseRangeRequest;
         } else if (token == "flush") {
           state = kParseFlush;
         } else if (token == "supported-algorithms") {
@@ -379,6 +382,10 @@ Configuration::Parse(const char *path)
         current_host_configuration->set_cache(token == "true");
         state = kParseStart;
         break;
+      case kParseRangeRequest:
+        current_host_configuration->set_range_request(token == "true");
+        state = kParseStart;
+        break;
       case kParseFlush:
         current_host_configuration->set_flush(token == "true");
         state = kParseStart;
diff --git a/plugins/compress/configuration.h b/plugins/compress/configuration.h
index 67e81ff..ffc1840 100644
--- a/plugins/compress/configuration.h
+++ b/plugins/compress/configuration.h
@@ -48,6 +48,7 @@ public:
     : host_(host),
       enabled_(true),
       cache_(true),
+      range_request_(false),
       remove_accept_encoding_(false),
       flush_(false),
       compression_algorithms_(ALGORITHM_GZIP),
@@ -66,6 +67,16 @@ public:
     enabled_ = x;
   }
   bool
+  range_request()
+  {
+    return range_request_;
+  }
+  void
+  set_range_request(bool x)
+  {
+    range_request_ = x;
+  }
+  bool
   cache()
   {
     return cache_;
@@ -131,6 +142,7 @@ private:
   std::string host_;
   bool enabled_;
   bool cache_;
+  bool range_request_;
   bool remove_accept_encoding_;
   bool flush_;
   int compression_algorithms_;

Reply via email to