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
6 changes: 6 additions & 0 deletions doc/admin-guide/plugins/compress.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------

Expand Down
14 changes: 13 additions & 1 deletion plugins/compress/compress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -661,13 +661,25 @@ 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);

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;
}

Expand Down
7 changes: 7 additions & 0 deletions plugins/compress/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ enum ParserState {
kParseRemoveAcceptEncoding,
kParseEnable,
kParseCache,
kParseRangeRequest,
kParseFlush,
kParseAllow,
kParseMinimumContentLength
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions plugins/compress/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class HostConfiguration : private atscppapi::noncopyable
: host_(host),
enabled_(true),
cache_(true),
range_request_(false),
remove_accept_encoding_(false),
flush_(false),
compression_algorithms_(ALGORITHM_GZIP),
Expand All @@ -66,6 +67,16 @@ class HostConfiguration : private atscppapi::noncopyable
enabled_ = x;
}
bool
range_request()
{
return range_request_;
}
void
set_range_request(bool x)
{
range_request_ = x;
}
bool
cache()
{
return cache_;
Expand Down Expand Up @@ -131,6 +142,7 @@ class HostConfiguration : private atscppapi::noncopyable
std::string host_;
bool enabled_;
bool cache_;
bool range_request_;
bool remove_accept_encoding_;
bool flush_;
int compression_algorithms_;
Expand Down