Skip to content

router: implement append/override of request/response headers to add (fixes #2003)#2025

Merged
mattklein123 merged 12 commits intoenvoyproxy:masterfrom
turbinelabs:fix-2003-header-append
Nov 15, 2017
Merged

router: implement append/override of request/response headers to add (fixes #2003)#2025
mattklein123 merged 12 commits intoenvoyproxy:masterfrom
turbinelabs:fix-2003-header-append

Conversation

@zuercher
Copy link
Member

@zuercher zuercher commented Nov 8, 2017

Modifies the Http::HeaderMap interface and implementation to allow replace semantics for non-static headers. Uses the new functionality to implement the append flag in envoy::v2::api::HeaderValueOption (with the caveat that the default behavior is append, which requires a change to the protobuf comment).

Fixes #2003

Risk Level: Low
The default path (append) is unchanged.

Testing:
Added unit tests with full code coverage over the modified code.

Release Notes:
Note change to default value of HeaderValueOption's append and that header override is now possible.

Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
…ixes envoyproxy#2003)

Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

cool stuff. few comments.

* the lifetime of any request/response using the string (since a codec may optimize for
* zero copy).
*/
HeaderString& operator=(HeaderString&& rhs);
Copy link
Member

Choose a reason for hiding this comment

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

Do we explicitly need the assignment operator? Would prefer not having compiler surprises here. Seems like we can basically just use the move function below? (Also, not sure comment about lifetime is accurate, the impl seems to handle all cases).


/**
* Set the header value by moving data into it.
*/
Copy link
Member

Choose a reason for hiding this comment

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

setMove for consistency?

string_length_ = ref_value.size();
}

HeaderString& HeaderString::operator=(HeaderString&& move_value) {
Copy link
Member

Choose a reason for hiding this comment

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

This is basically the same code as the move constructor. Can we put code in common utility function and just call freeDynamic() followed by that function?


/**
* Set a header via full move.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be public?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, in which case it doesn't even need to exist.

Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>

/**
* Set the header value by moving data into it.
*/
Copy link
Member

Choose a reason for hiding this comment

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

FYI I didn't mean for you to revert all the perf stuff you did. I was just saying to remove HeaderString& operator=, rename this to setMove(), and then just call setMove() wherever you need it. I'm fine either way though. LMK.

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently I didn't ctrl-c that push fast enough.

Anyway, I decided this is easier to understand and arguably more correct (the rule is route headers before vhost headers before global headers, so they should come out in the right order even in the face of set-after-append).

It's slightly slower in that it always adds a new HeaderEntry, but I think that's probably swamped by having to iterate over the headers to remove duplicate keys.

Copy link
Member Author

Choose a reason for hiding this comment

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

That said, we could have both if I undid this last commit and then changed the updateByKey search to iterate over the headers in reverse order.

Copy link
Member

Choose a reason for hiding this comment

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

OK sounds good. The upside I can see about the update code that you had is it would update in place and not effect ordering. What you have now will move it to the back of the list which is arguably not as good. I don't think it matters that much though.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine either way, just LMK if you are going to change again.

*
* @param key specifies the name of the header to set; it WILL be copied.
* @param value specifies the value of the header to set; it WILL be copied.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Are the two setCopy() calls added used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

The string version is used in TestHeaderMapImpl to provide a convenience function for tests.

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't the test version just do remove followed by add? (I guess now that you removed update, couldn't it all just work that way)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems to me that having explicit method that do this work allows for future changes to optimize the set path, even if it's just remove/add under the covers now. But if you want, I can yank out all the set methods and move the remove calls into the router.

Copy link
Member

Choose a reason for hiding this comment

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

You already wrote the optimized code but then you deleted it. 😉 I don't care either way. I mostly want to make sure that if we have functions they are actually used. If you want to keep the ones that are called but for example remove the setCopy stuff that isn't used other than test (and implement that in terms of remove/add) that's fine. LMK.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok. I'll remove the unused ones.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for this additional header mutation support.

*
* @param key specifies the name of the header to set; it WILL NOT be copied.
* @param value specifies the value of the header to set; it WILL NOT be copied.
*/
Copy link
Member

Choose a reason for hiding this comment

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

It might be less verbose to just make this a bool arg on the existing add*, but I don't think it's a big deal.

namespace {

Router::HeaderAddition
make_header_to_add(const envoy::api::v2::HeaderValueOption& header_value_option) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: makeHeaderToAdd(..).

Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
htuch
htuch previously approved these changes Nov 15, 2017
ContainerEq(config.responseHeadersToRemove()));
}

TEST(RouteMatcherTest, TestAddRemoveReqRespHeadersWithAppendFalse) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I like one liners above tests explaining what they do.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM other than tiny nits.


virtual const std::string format(const Envoy::AccessLog::RequestInfo& request_info) const PURE;

/*
Copy link
Member

Choose a reason for hiding this comment

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

nit: /**

Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
@mattklein123 mattklein123 merged commit 9f7f8f5 into envoyproxy:master Nov 15, 2017
@zuercher zuercher deleted the fix-2003-header-append branch December 8, 2017 18:27
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
* Improve performance by removing MD5 for check cache keys (envoyproxy#2002)

* Improve performance by removing MD5 for check cache keys

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

* not to allocate memory from stack

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

* Make debug string readable

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

* alts: remove ALTS (envoyproxy#2003)

Signed-off-by: Lizan Zhou <lizan@tetrate.io>

* Use std::hash for check cache. (envoyproxy#2009)

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

* Remove tests to compare signature values (envoyproxy#2015)

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

* update sample envoy config to latest version (envoyproxy#2016)

* Add a new TCP cluster rewrite filter (envoyproxy#2017)

* Add a new TCP cluster rewrite filter

This commit adds a new TCP cluster rewrite filter which allows users to
rewrite TCP cluster names obtained via TLS SNI by matching via regex
configuration.

Signed-off-by: Venil Noronha <veniln@vmware.com>

* Make TCP cluster rewrite stackable on SNI filter

This commit updates the TCP Cluster Rewrite filter to be stackable on
the SNI Cluster filter.

Signed-off-by: Venil Noronha <veniln@vmware.com>

* Update TCP Cluster Rewrite filter name (envoyproxy#2019)

This commit updates the TCP Cluster Rewrite filter name to
envoy.filters.network.tcp_cluster_rewrite.

Signed-off-by: Venil Noronha <veniln@vmware.com>

* Enable TCP Cluster Rewrite filter registration (envoyproxy#2021)

This commit enables the static registration of the TCP Cluster Rewrite
filter by updating the build configuration.

Signed-off-by: Venil Noronha <veniln@vmware.com>

* Update Envoy SHA to 4ef8562 (envoyproxy#2023)

Envoy /server_info API was inconsistent intermittently causing errors on
a Proxy update on Istio. This update will bring in the API fix to Istio.

Signed-off-by: Venil Noronha <veniln@vmware.com>

* add proxy postsubmit periodic (envoyproxy#2025)
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
* Improve performance by removing MD5 for check cache keys (envoyproxy#2002)

* Improve performance by removing MD5 for check cache keys

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

* not to allocate memory from stack

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

* Make debug string readable

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

* alts: remove ALTS (envoyproxy#2003)

Signed-off-by: Lizan Zhou <lizan@tetrate.io>

* Use std::hash for check cache. (envoyproxy#2009)

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

* Remove tests to compare signature values (envoyproxy#2015)

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

* update sample envoy config to latest version (envoyproxy#2016)

* Add a new TCP cluster rewrite filter (envoyproxy#2017)

* Add a new TCP cluster rewrite filter

This commit adds a new TCP cluster rewrite filter which allows users to
rewrite TCP cluster names obtained via TLS SNI by matching via regex
configuration.

Signed-off-by: Venil Noronha <veniln@vmware.com>

* Make TCP cluster rewrite stackable on SNI filter

This commit updates the TCP Cluster Rewrite filter to be stackable on
the SNI Cluster filter.

Signed-off-by: Venil Noronha <veniln@vmware.com>

* Update TCP Cluster Rewrite filter name (envoyproxy#2019)

This commit updates the TCP Cluster Rewrite filter name to
envoy.filters.network.tcp_cluster_rewrite.

Signed-off-by: Venil Noronha <veniln@vmware.com>

* Enable TCP Cluster Rewrite filter registration (envoyproxy#2021)

This commit enables the static registration of the TCP Cluster Rewrite
filter by updating the build configuration.

Signed-off-by: Venil Noronha <veniln@vmware.com>

* Update Envoy SHA to 4ef8562 (envoyproxy#2023)

Envoy /server_info API was inconsistent intermittently causing errors on
a Proxy update on Istio. This update will bring in the API fix to Istio.

Signed-off-by: Venil Noronha <veniln@vmware.com>

* add proxy postsubmit periodic (envoyproxy#2025)

* Update Envoy SHA to c41fa71 (envoyproxy#2029)

* Update Envoy SHA

Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>

* Fix format.

Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>

* bazel: Allow to distdir all dependencies (envoyproxy#2034)

To use --distdir option of Bazel (which allows to use previously
fetched tarballs instead of downloading dependencies during
build), all dependencies should use http instead of git and need
to have sha256 sums specified.

Signed-off-by: Michal Rostecki <mrostecki@suse.de>

* bazel: Remove BoringSSL repository (envoyproxy#2035)

Pull request envoyproxy#2002 removed signature calculation which was using
BoringSSL as a dependency. BoringSSL is not needed anymore.

Signed-off-by: Michal Rostecki <mrostecki@suse.de>

* Update Envoy SHA to fcc68f1 (envoyproxy#2037)

* Update Envoy SHA to fcc68f1

Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>

* Update SHA256

Signed-off-by: JimmyCYJ <jimmychen.0102@gmail.com>
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: JP Simard <jp@jpsim.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants