Skip to content

Introduce StringMatcher to the compressor - #46458

Open
Vexali0n wants to merge 4 commits into
envoyproxy:mainfrom
Vexali0n:compressor-wildcard-support
Open

Introduce StringMatcher to the compressor#46458
Vexali0n wants to merge 4 commits into
envoyproxy:mainfrom
Vexali0n:compressor-wildcard-support

Conversation

@Vexali0n

@Vexali0n Vexali0n commented Jul 30, 2026

Copy link
Copy Markdown

Commit Message:
This PR adds new functionality of the compressor module to allow usage of StringMatcher, to allow more than just exact match for the content_type as it is at the moment.

Additional Description:
Current state of compressor allows only to use exact match for content types or it will fallback to the default list. There is no way how to specify wildcards to allow extreme amount of different content types as it is in our case. Generative AI has been used.

Risk Level:
Medium

Testing:
In addition to the written tests in the PR I have compiled the proxy locally, started up the proxy and tested against multiple envoy proxy configurations to prove envoy StringMatcher is supported and response is compressed while original logic of exact match and default list still function correctly.

Docs Changes:
New field content_type_matcher introduced for the compressor

Release Notes:
compressor: added support for content_type_matcher in CommonDirectionConfig, allowing fine-grained MIME type matching via string matchers.

[Optional Fixes #Issue]
Fixes #46344

FYI:
Original PR was #46374 where I was told to introduce StringMatcher into the compressor hence here is the new suggested solution.

@repokitteh-read-only

Copy link
Copy Markdown

Hi @Vexali0n, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #46458 was opened by Vexali0n.

see: more, trace.

@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @adisuissa
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #46458 was opened by Vexali0n.

see: more, trace.

@Vexali0n
Vexali0n force-pushed the compressor-wildcard-support branch from d427da2 to e85c957 Compare July 30, 2026 11:44
@Vexali0n
Vexali0n had a problem deploying to external-contributors July 30, 2026 11:44 — with GitHub Actions Error
@Vexali0n
Vexali0n had a problem deploying to external-contributors July 30, 2026 12:04 — with GitHub Actions Error
Vexali0n added 2 commits July 30, 2026 14:04
…cher'

Signed-off-by: Vexali0n <adam.richter218@gmail.com>
Signed-off-by: Vexali0n <adam.richter218@gmail.com>
@Vexali0n
Vexali0n force-pushed the compressor-wildcard-support branch from 3080c20 to 001674e Compare July 30, 2026 12:04
@Vexali0n
Vexali0n temporarily deployed to external-contributors July 30, 2026 12:05 — with GitHub Actions Inactive
@KBaichoo KBaichoo self-assigned this Jul 30, 2026

@KBaichoo KBaichoo left a comment

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.

Thank you for working on this

/wait

// When this field is specified, the default content type list is not used.
// Compression is applied when at least one configured matcher matches the
// response content-type header.
repeated type.matcher.v3.StringMatcher content_type_matcher = 4;

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.

worth documenting what happens if both of content-type and content_type_matcher is used -- e.g. currently they get merged as per implementation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

proto updated to explain more in detail

Comment on lines +751 to +757
if (!content_type_matchers_.empty()) {
for (const auto& matcher : content_type_matchers_) {
if (matcher->match(value)) {
return true;
}
}
}

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.

Media types are case insensitive but the content_type_matcher here are case sensitive which is a bit of a mismatch. Consider lower casing the value and noting this in the proto that matches occur on lowercases values.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Value is lower cased and mentioned in the proto that users should type in lower cased valuses for the content types.

uint32_t minimumLength() const { return min_content_length_; }
bool isMinimumContentLength(const Http::RequestOrResponseHeaderMap& headers) const;
bool isContentTypeAllowed(const Http::RequestOrResponseHeaderMap& headers) const;
const std::vector<Matchers::StringMatcherPtr>& contentTypeMatchers() const {

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 this isn't used?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed, leftover.

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.

This is now dead but we end up now re-generating this in every loop below, can we instead normalize this once and pass it in below in an overloaded case?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Overload has been added to not normalize value on each loop and on top of that I have added normalization content type helper function

repeated string content_type = 3;

// Allows specifying which mime-types yield compression using
// envoy.type.matcher.v3.StringMatcher.

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.

High-level API question: would it make sense to add a generic matcher extension here (instead of adding each of them individually)?

…alization helper function

Signed-off-by: Vexali0n <adam.richter218@gmail.com>
Signed-off-by: Vexali0n <adam.richter218@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compression Content Types

3 participants