Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
41688bb
filter_gzip: implemented gzip http filter
Nov 21, 2017
f2d771c
filter_gzip: fixed comments
Nov 21, 2017
ab41a28
filter_gzip: included compression strategy in config, simplified logi…
Nov 22, 2017
e6a60dd
filter_gzip: wip - changes reqested
Dec 2, 2017
64f4b32
filter_gzip: wip - inspect content-length
Dec 3, 2017
1790374
filter_gzip: wip - included cache-control, content-type, etag and las…
Dec 4, 2017
63da733
filter_gzip: addressed suggested modifications
Dec 5, 2017
0916c89
filter_gzip: suggested modifications second pass
Dec 6, 2017
8b6cde4
filter_gzip: removed unnamed namespace
Dec 6, 2017
79bebed
filter_gzip: removed enums from json schema
Dec 11, 2017
4a948a4
filter_gzip: wip - converted filter to V2
Dec 13, 2017
056cec5
filter_gzip: wip - updated unit tests
Dec 14, 2017
b1703ac
filter_gzip: updated integration tests
Dec 14, 2017
92cce05
filter_gzip: converted to V2 api and improved test coverage
Dec 15, 2017
34ab3b0
filter_gzip: removed auto from function
Dec 15, 2017
e318d8b
filter_gzip: made small improvements to GzipFilterConfig class and in…
Dec 18, 2017
63cedce
filter_gzip: changed const assigment to braced-init
Dec 18, 2017
ae49a8c
filter_gzip: included the requested changes
Dec 19, 2017
6aeca5b
filter_gzip: updated filter to support configurable window bits
Dec 20, 2017
f6c42a2
filter_gzip: addressed requested changes, updated config and added mo…
Dec 21, 2017
328748d
filter_gzip: modified comment
Dec 21, 2017
4b1c919
filter_gzip: changed isContentTypeAllowed to use fast lookup and remo…
Dec 28, 2017
55807b8
filter_gzip: did changes suggested in code review
Dec 30, 2017
4e83abb
filter_gzip: fixed format
Dec 30, 2017
b584114
filter_gzip: applied changes suggested in code review
Jan 4, 2018
3c44d5b
filter_gzip: fixed tests
Jan 4, 2018
f254981
filter_gzip: improved performance and other critical parts of the design
Jan 10, 2018
6f7705b
filter_gzip: fixed thread sanitizer warning
Jan 12, 2018
cb6eae5
filter_gzip: wip code review changes
Jan 18, 2018
c75cf78
filter_gzip: fixed integration test
Jan 18, 2018
c1fa7b5
filter_gzip: resync with data-plane api and completed etag option
Jan 22, 2018
02ca187
filter_gzip: fixed comment
Jan 22, 2018
a7ac555
filter_gzip: modified private member function insertVaryHeader
Jan 23, 2018
6df4302
filter_gzip: code review changes
Jan 24, 2018
e901c1e
filter_gzip: add a comment to contentTypeSet and removed unecessary e…
Jan 24, 2018
7ceae22
filter_gzip: updated repository_locations
Jan 25, 2018
2fc9fc2
filter_gzip: code review changes
Jan 26, 2018
ba72b06
filter_gzip: fixed runtime error detected by asan
Jan 26, 2018
67272de
filter_gzip: made comment in todo clearer
Jan 27, 2018
8dd8a75
filter_gzip: dropped disableOnLastModifiedHeader and added friend cla…
Jan 28, 2018
3cdec34
filter_gzip: fixed format
Jan 28, 2018
62808a7
filter_gzip: code review changes
Feb 3, 2018
dad5fad
filter_gzip: updated repository locations and rebased
Feb 4, 2018
1f0d0cf
filter_gzip: fixed conflicts
Feb 4, 2018
16a3a96
filter_gzip: rebased and added option to remove accept-encoding header
Feb 5, 2018
b99155d
filter_gzip: changed vary header values to be case sensitive and upda…
Feb 6, 2018
cd363a7
filter_gzip: added support to handle case-insensitive header values
Feb 8, 2018
35d4bd3
filter_gzip: merged master and removed V1 support
Feb 8, 2018
f291227
filter_gzip: merged master and fixed format
Feb 8, 2018
ce30782
filter_gzip: removed unused code from filter_json
Feb 8, 2018
04d5ce8
filter_gzip: removed the remaining V1 code
Feb 8, 2018
a31fe2e
filter_gzip: resolved conflict
Feb 8, 2018
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
2 changes: 1 addition & 1 deletion bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ REPOSITORY_LOCATIONS = dict(
urls = ["https://github.com/google/protobuf/archive/v3.5.0.tar.gz"],
),
envoy_api = dict(
commit = "4e533f22baced334c4aba68fb60c5fc439f0fe9c",
commit = "11adebcc8538bfe9facf6cef2168bb2885eb2c13",
remote = "https://github.com/envoyproxy/data-plane-api",
),
grpc_httpjson_transcoding = dict(
Expand Down
5 changes: 5 additions & 0 deletions include/envoy/http/header_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class HeaderEntry {
* O(1) access to these headers without even a hash lookup.
*/
#define ALL_INLINE_HEADERS(HEADER_FUNC) \
HEADER_FUNC(AcceptEncoding) \
HEADER_FUNC(AccessControlRequestHeaders) \
HEADER_FUNC(AccessControlRequestMethod) \
HEADER_FUNC(AccessControlAllowOrigin) \
Expand All @@ -243,6 +244,7 @@ class HeaderEntry {
HEADER_FUNC(CacheControl) \
HEADER_FUNC(ClientTraceId) \
HEADER_FUNC(Connection) \
HEADER_FUNC(ContentEncoding) \
HEADER_FUNC(ContentLength) \
HEADER_FUNC(ContentType) \
HEADER_FUNC(Date) \
Expand All @@ -266,6 +268,7 @@ class HeaderEntry {
HEADER_FUNC(EnvoyUpstreamRequestTimeoutAltResponse) \
HEADER_FUNC(EnvoyUpstreamRequestTimeoutMs) \
HEADER_FUNC(EnvoyUpstreamServiceTime) \
HEADER_FUNC(Etag) \
HEADER_FUNC(Expect) \
HEADER_FUNC(ForwardedClientCert) \
HEADER_FUNC(ForwardedFor) \
Expand All @@ -275,6 +278,7 @@ class HeaderEntry {
HEADER_FUNC(GrpcStatus) \
HEADER_FUNC(Host) \
HEADER_FUNC(KeepAlive) \
HEADER_FUNC(LastModified) \
HEADER_FUNC(Method) \
HEADER_FUNC(Origin) \
HEADER_FUNC(OtSpanContext) \
Expand All @@ -289,6 +293,7 @@ class HeaderEntry {
HEADER_FUNC(TransferEncoding) \
HEADER_FUNC(Upgrade) \
HEADER_FUNC(UserAgent) \
HEADER_FUNC(Vary) \
HEADER_FUNC(XB3TraceId) \
HEADER_FUNC(XB3SpanId) \
HEADER_FUNC(XB3ParentSpanId) \
Expand Down
1 change: 1 addition & 0 deletions source/common/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ envoy_cc_library(
":assert_lib",
"//include/envoy/common:interval_set_interface",
"//include/envoy/common:time_interface",
"//source/common/common:hash_lib",
],
)

Expand Down
17 changes: 17 additions & 0 deletions source/common/common/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <string>

#include "absl/strings/ascii.h"
#include "absl/strings/string_view.h"
#include "xxhash.h"

Expand All @@ -14,6 +15,22 @@ class HashUtil {
* See https://github.com/Cyan4973/xxHash for details.
*/
static uint64_t xxHash64(absl::string_view input) { return XXH64(input.data(), input.size(), 0); }

/**
* TODO(gsagula): extend xxHash to handle case-insensitive.
*
* Return 64-bit hash representation of string ingnoring case.
* See djb2 (http://www.cse.yorku.ca/~oz/hash.html) for more details.
* @param input supplies the string view.
* @return 64-bit hash representation of the supplied string view.
*/
static uint64_t djb2CaseInsensitiveHash(absl::string_view input) {
uint64_t hash = 5381;
for (unsigned char c : input) {
hash += ((hash << 5) + hash) + absl::ascii_tolower(c);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like an unintended deviation from the original DJB2 hash having:

      hash += ((hash << 5) + hash) + absl::ascii_tolower(c);

instead of:

      hash = ((hash << 5) + hash) + absl::ascii_tolower(c);

While at it, a typo in ingnoring.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andre-rosa can i suggest opening a PR with your suggested change - seems like the typo is fixed already so i would suggest looking at current main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your answer. Please check #21787.

};
return hash;
}
};

} // namespace Envoy
51 changes: 45 additions & 6 deletions source/common/common/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
#include <cstdint>
#include <iterator>
#include <string>
#include <vector>

#include "envoy/common/exception.h"

#include "common/common/assert.h"
#include "common/common/fmt.h"
#include "common/common/hash.h"

#include "absl/strings/ascii.h"
#include "absl/strings/internal/memutil.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include "spdlog/spdlog.h"
Expand Down Expand Up @@ -102,25 +103,54 @@ absl::string_view StringUtil::trim(absl::string_view source) { return ltrim(rtri

bool StringUtil::findToken(absl::string_view source, absl::string_view delimiters,
absl::string_view key_token, bool trim_whitespace) {
const std::vector<absl::string_view> tokens = splitToken(source, delimiters, trim_whitespace);
const auto tokens = splitToken(source, delimiters, trim_whitespace);
if (trim_whitespace) {
for (auto token : tokens) {
for (const auto token : tokens) {
if (key_token == trim(token)) {
return true;
}
}
return false;
}

return std::find(tokens.begin(), tokens.end(), key_token) != tokens.end();
}

absl::string_view StringUtil::cropRight(absl::string_view source, absl::string_view delimiter,
bool trim_whitespace) {
bool StringUtil::caseFindToken(absl::string_view source, absl::string_view delimiters,
absl::string_view key_token, bool trim_whitespace) {
const auto tokens = splitToken(source, delimiters, trim_whitespace);
std::function<bool(absl::string_view)> predicate;

if (trim_whitespace) {
predicate = [&](absl::string_view token) { return caseCompare(key_token, trim(token)); };
} else {
predicate = [&](absl::string_view token) { return caseCompare(key_token, token); };
}

return std::find_if(tokens.begin(), tokens.end(), predicate) != tokens.end();
}

bool StringUtil::caseCompare(absl::string_view lhs, absl::string_view rhs) {
if (rhs.size() != lhs.size()) {
return false;
}
return absl::strings_internal::memcasecmp(rhs.data(), lhs.data(), rhs.size()) == 0;
}

absl::string_view StringUtil::cropRight(absl::string_view source, absl::string_view delimiter) {
const absl::string_view::size_type pos = source.find(delimiter);
if (pos != absl::string_view::npos) {
source.remove_suffix(source.size() - pos);
}
return trim_whitespace ? rtrim(source) : source;
return source;
}

absl::string_view StringUtil::cropLeft(absl::string_view source, absl::string_view delimiter) {
const absl::string_view::size_type pos = source.find(delimiter);
if (pos != absl::string_view::npos) {
source.remove_prefix(pos + delimiter.size());
}
return source;
}

std::vector<absl::string_view> StringUtil::splitToken(absl::string_view source,
Expand Down Expand Up @@ -239,6 +269,15 @@ std::string StringUtil::toUpper(absl::string_view s) {
return upper_s;
}

bool StringUtil::CaseInsensitiveCompare::operator()(absl::string_view lhs,
absl::string_view rhs) const {
return StringUtil::caseCompare(lhs, rhs);
}

uint64_t StringUtil::CaseInsensitiveHash::operator()(absl::string_view key) const {
return HashUtil::djb2CaseInsensitiveHash(key);
}

std::string StringUtil::removeCharacters(const absl::string_view& str,
const IntervalSet<size_t>& remove_characters) {
std::string ret;
Expand Down
79 changes: 74 additions & 5 deletions source/common/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <set>
#include <sstream>
#include <string>
#include <unordered_set>
#include <vector>

#include "envoy/common/interval_set.h"
Expand Down Expand Up @@ -170,7 +171,7 @@ class StringUtil {
* string views; default = true.
* @return true if found and false otherwise.
*
* E.g,
* E.g.,
*
* findToken("A=5; b", "=;", "5") . true
* findToken("A=5; b", "=;", "A=5") . false
Expand All @@ -181,17 +182,60 @@ class StringUtil {
static bool findToken(absl::string_view source, absl::string_view delimiters,
absl::string_view token, bool trim_whitespace = true);

/**
* Look up for a token in a delimiter-separated string view ignoring case
* sensitivity.
* @param source supplies the delimiter-separated string view.
* @param multi-delimiter supplies chars used to split the delimiter-separated string view.
* @param token supplies the lookup string view.
* @param trim_whitespace remove leading and trailing whitespaces from each of the split
* string views; default = true.
* @return true if found a string that is semantically the same and false otherwise.
*
* E.g.,
*
* findToken("hello; world", ";", "HELLO") . true
*/
static bool caseFindToken(absl::string_view source, absl::string_view delimiters,
absl::string_view key_token, bool trim_whitespace = true);

/**
* Compare one string view with another string view ignoring case sensitivity.
* @param lhs supplies the first string view.
* @param rhs supplies the second string view.
* @return true if strings are semantically the same and false otherwise.
*
* E.g.,
*
* findToken("hello; world", ";", "HELLO") . true
*/
static bool caseCompare(absl::string_view lhs, absl::string_view rhs);

/**
* Crop characters from a string view starting at the first character of the matched
* delimiter string view until the end of the source string view.
* @param source supplies the string view to be processed.
* @param delimiter supplies the string view that delimits the starting point for deletion.
* @param trim_whitespace remove leading and trailing whitespaces from each of the split
* string views; default = true.
* @return sub-string of the string view if any.
*
* E.g.,
*
* cropRight("foo ; ; ; ; ; ; ", ";") == "foo "
*/
static absl::string_view cropRight(absl::string_view source, absl::string_view delimiters,
bool trim_whitespace = true);
static absl::string_view cropRight(absl::string_view source, absl::string_view delimiters);

/**
* Crop characters from a string view starting at the first character of the matched
* delimiter string view until the begining of the source string view.
* @param source supplies the string view to be processed.
* @param delimiter supplies the string view that delimits the starting point for deletion.
* @return sub-string of the string view if any.
*
* E.g.,
*
* cropLeft("foo ; ; ; ; ; ", ";") == " ; ; ; ; "
*/
static absl::string_view cropLeft(absl::string_view source, absl::string_view delimiters);

/**
* Split a delimiter-separated string view.
Expand Down Expand Up @@ -259,6 +303,31 @@ class StringUtil {
*/
static std::string toUpper(absl::string_view s);

/**
* Callable struct that returns the result of string comparison ignoring case.
* @param lhs supplies the first string view.
* @param rhs supplies the second string view.
* @return true if strings are semantically the same and false otherwise.
*/
struct CaseInsensitiveCompare {
bool operator()(absl::string_view lhs, absl::string_view rhs) const;
};

/**
* Callable struct that returns the hash representation of a case-insensitive string_view input.
* @param key supplies the string view.
* @return uint64_t hash representation of the supplied string view.
*/
struct CaseInsensitiveHash {
uint64_t operator()(absl::string_view key) const;
};

/**
* Definition of unordered set of case-insensitive std::string.
*/
typedef std::unordered_set<std::string, CaseInsensitiveHash, CaseInsensitiveCompare>
CaseUnorderedSet;

/**
* Removes all the character indices from str contained in the interval-set.
* @param str the string containing the characters to be removed.
Expand Down
7 changes: 4 additions & 3 deletions source/common/compressor/zlib_compressor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class ZlibCompressorImpl : public Compressor {
/**
* Enum values used to set compression level during initialization.
* best: gives best compression.
* speed: gives best.
* standard: gives normal compression. (default)
* speed: gives best performance.
* standard: requests a default compromise between speed and compression. (default) @see zlib
* manual.
*/
enum class CompressionLevel : int64_t {
Best = 9,
Expand All @@ -41,7 +42,7 @@ class ZlibCompressorImpl : public Compressor {
* filtered: used for data produced by a filter. (or predictor) @see Z_FILTERED (zlib manual)
* huffman: used to enforce Huffman encoding. @see RFC 1951
* rle: used to limit match distances to one. (Run-length encoding)
* standard: used for normal data. (default) @see Z_DEFAULT_STRATEGY (zlib manual)
* standard: used for normal data. (default) @see Z_DEFAULT_STRATEGY in zlib manual.
*/
enum class CompressionStrategy : uint64_t {
Filtered = 1,
Expand Down
1 change: 1 addition & 0 deletions source/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ envoy_cc_library(
"//source/common/protobuf:utility_lib",
"@envoy_api//envoy/config/filter/http/buffer/v2:buffer_cc",
"@envoy_api//envoy/config/filter/http/fault/v2:fault_cc",
"@envoy_api//envoy/config/filter/http/gzip/v2:gzip_cc",
"@envoy_api//envoy/config/filter/http/health_check/v2:health_check_cc",
"@envoy_api//envoy/config/filter/http/lua/v2:lua_cc",
"@envoy_api//envoy/config/filter/http/rate_limit/v2:rate_limit_cc",
Expand Down
1 change: 0 additions & 1 deletion source/common/config/filter_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,5 @@ class FilterJson {
static void translateSquashConfig(const Json::Object& json_config,
envoy::config::filter::http::squash::v2::Squash& proto_config);
};

} // namespace Config
} // namespace Envoy
2 changes: 2 additions & 0 deletions source/common/config/well_known_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class HttpFilterNameValues {
const std::string GRPC_JSON_TRANSCODER = "envoy.grpc_json_transcoder";
// GRPC web filter
const std::string GRPC_WEB = "envoy.grpc_web";
// Gzip filter
const std::string ENVOY_GZIP = "envoy.gzip";
// IP tagging filter
const std::string IP_TAGGING = "envoy.ip_tagging";
// Rate limit filter
Expand Down
2 changes: 1 addition & 1 deletion source/common/decompressor/zlib_decompressor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ZlibDecompressorImpl : public Decompressor {
private:
bool inflateNext();

uint64_t chunk_size_;
const uint64_t chunk_size_;
bool initialized_;

std::unique_ptr<unsigned char[]> chunk_char_ptr_;
Expand Down
18 changes: 18 additions & 0 deletions source/common/http/filter/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "gzip_filter_lib",
srcs = ["gzip_filter.cc"],
hdrs = ["gzip_filter.h"],
deps = [
"//include/envoy/http:filter_interface",
"//include/envoy/json:json_object_interface",
"//source/common/buffer:buffer_lib",
"//source/common/compressor:compressor_lib",
"//source/common/http:header_map_lib",
"//source/common/http:headers_lib",
"//source/common/json:config_schemas_lib",
"//source/common/json:json_validator_lib",
"//source/common/protobuf",
"@envoy_api//envoy/config/filter/http/gzip/v2:gzip_cc",
],
)

envoy_cc_library(
name = "ip_tagging_filter_lib",
srcs = ["ip_tagging_filter.cc"],
Expand Down
Loading