router: implement append/override of request/response headers to add (fixes #2003)#2025
Conversation
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>
mattklein123
left a comment
There was a problem hiding this comment.
cool stuff. few comments.
include/envoy/http/header_map.h
Outdated
| * the lifetime of any request/response using the string (since a codec may optimize for | ||
| * zero copy). | ||
| */ | ||
| HeaderString& operator=(HeaderString&& rhs); |
There was a problem hiding this comment.
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).
include/envoy/http/header_map.h
Outdated
|
|
||
| /** | ||
| * Set the header value by moving data into it. | ||
| */ |
| string_length_ = ref_value.size(); | ||
| } | ||
|
|
||
| HeaderString& HeaderString::operator=(HeaderString&& move_value) { |
There was a problem hiding this comment.
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?
source/common/http/header_map_impl.h
Outdated
|
|
||
| /** | ||
| * Set a header via full move. | ||
| */ |
There was a problem hiding this comment.
Does this need to be public?
There was a problem hiding this comment.
No, in which case it doesn't even need to exist.
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
include/envoy/http/header_map.h
Outdated
|
|
||
| /** | ||
| * Set the header value by moving data into it. | ||
| */ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I'm fine either way, just LMK if you are going to change again.
include/envoy/http/header_map.h
Outdated
| * | ||
| * @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. | ||
| */ |
There was a problem hiding this comment.
Are the two setCopy() calls added used anywhere?
There was a problem hiding this comment.
The string version is used in TestHeaderMapImpl to provide a convenience function for tests.
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ok. I'll remove the unused ones.
htuch
left a comment
There was a problem hiding this comment.
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. | ||
| */ |
There was a problem hiding this comment.
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.
source/common/router/config_impl.cc
Outdated
| namespace { | ||
|
|
||
| Router::HeaderAddition | ||
| make_header_to_add(const envoy::api::v2::HeaderValueOption& header_value_option) { |
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>
| ContainerEq(config.responseHeadersToRemove())); | ||
| } | ||
|
|
||
| TEST(RouteMatcherTest, TestAddRemoveReqRespHeadersWithAppendFalse) { |
There was a problem hiding this comment.
Nit: I like one liners above tests explaining what they do.
mattklein123
left a comment
There was a problem hiding this comment.
LGTM other than tiny nits.
|
|
||
| virtual const std::string format(const Envoy::AccessLog::RequestInfo& request_info) const PURE; | ||
|
|
||
| /* |
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
* 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)
* 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>
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.