Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[thrift_proxy] Replace local HeaderMap with Http::HeaderMap[Impl] #4169

Conversation

brirams
Copy link
Contributor

@brirams brirams commented Aug 15, 2018

Description:
As part of implementing header matching in the thrift proxy, we'll want to re-use a lot of the existing machinery that exists for http header matching. To make that more straightforward, use the http header implementation in the thrift proxy instead of our own rolled one.

Risk Level:
low

Testing:
tests, new and old, pass.

Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Thank you!

@@ -123,11 +48,14 @@ class MessageMetadata {
MessageType messageType() const { return msg_type_.value(); }
void setMessageType(MessageType msg_type) { msg_type_ = msg_type; }

void addHeader(Header&& header) { headers_.add(std::move(header)); }
void addHeader(const std::string key, const std::string value) {
headers_.addReference(Http::LowerCaseString(key), value);
Copy link
Member

Choose a reason for hiding this comment

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

Note the docs on addReference in include/envoy/http/header_map.h -- it's expecting key and value to live as long as headers_ does and they'll get destroyed when this method exits. I think you need to use addCopy.

That said, I think now that we're using the Http::HeaderMapImpl, we should add a Http::HeaderMap& headers() method (keep the existing one), delete addHeader, and let callers use the full HeaderMap interface. Then the caller, who may know more about the lifetime of the data, can make an informed decision on how to set the header.

@@ -56,8 +56,7 @@ TEST(MessageMetadataTest, Headers) {
MessageMetadata metadata;

EXPECT_EQ(metadata.headers().size(), 0);

metadata.addHeader("k", "v");
metadata.headers().addReference(Http::LowerCaseString("k"), "v");
Copy link
Member

Choose a reason for hiding this comment

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

addCopy -- those strings still don't live beyond this line of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bah you're right!

@zuercher
Copy link
Member

tag @rgs1 and @fishcakez

…apImpl

Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
… to mutate Http::HeaderMap

Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
@brirams brirams force-pushed the brirams/#5555/thrift_proxy/use_http_header_impl branch from c56928d to 24952b1 Compare August 17, 2018 17:10
@brirams
Copy link
Contributor Author

brirams commented Aug 17, 2018

mistakenly rebased my work vs. merging master. sorry, ya'll.

Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Cool. One little thing, but otherwise 👍

@@ -296,7 +300,7 @@ void HeaderTransportImpl::writeVarString(Buffer::Instance& buffer, const std::st
if (len == 0) {
return;
}
buffer.add(str);
buffer.add(str.data(), str.length());
Copy link
Member

Choose a reason for hiding this comment

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

Just use len

Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
@@ -146,7 +146,7 @@ bool HeaderTransportImpl::decodeFrameStart(Buffer::Instance& buffer, MessageMeta
while (num_headers-- > 0) {
std::string key = drainVarString(buffer, header_size, "header key");
Copy link
Member

Choose a reason for hiding this comment

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

nit: couldn't key be constructed here as a LowerCaseString?

@@ -146,7 +146,7 @@ bool HeaderTransportImpl::decodeFrameStart(Buffer::Instance& buffer, MessageMeta
while (num_headers-- > 0) {
std::string key = drainVarString(buffer, header_size, "header key");
std::string value = drainVarString(buffer, header_size, "header value");
Copy link
Member

Choose a reason for hiding this comment

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

nit: should key/value be consts?

Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
Copy link
Member

@rgs1 rgs1 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!

Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

👍

@zuercher zuercher merged commit fbf6af7 into envoyproxy:master Aug 17, 2018
@brirams brirams deleted the brirams/#5555/thrift_proxy/use_http_header_impl branch August 20, 2018 16:28
snowp added a commit to snowp/envoy that referenced this pull request Aug 20, 2018
* origin/master: (34 commits)
  fuzz: fixes oss-fuzz: 9895 (envoyproxy#4189)
  docs: added developer docs for pprof/tcmalloc testing (envoyproxy#4194)
  fix sometimes returns response body to HEAD requests (envoyproxy#3985)
  admin: fix config dump order (envoyproxy#4197)
  thrift: allow translation between downstream and upstream protocols (envoyproxy#4136)
  Use local_info.node() instead of bootstrap.node() whenever possible (envoyproxy#4120)
  upstream: allow extension protocol options to be used with http filters (envoyproxy#4165)
  [thrift_proxy] Replace local HeaderMap with Http::HeaderMap[Impl] (envoyproxy#4169)
  docs: improve gRPC-JSON filter doc (envoyproxy#4184)
  stats: refactoring MetricImpl without strings (envoyproxy#4190)
  fuzz: coverage profile generation instructions. (envoyproxy#4193)
  upstream: rebuild cluster when health check config is changed (envoyproxy#4075)
  build: use clang-6.0. (envoyproxy#4168)
  thrift_proxy: introduce header transport (envoyproxy#4082)
  tcp: allow connection pool callers to store protocol state (envoyproxy#4131)
  configs: match latest API changes (envoyproxy#4185)
  Fix wrong mock function name. (envoyproxy#4187)
  Bump yaml-cpp so it builds with Visual Studio 15.8 (envoyproxy#4182)
  Converting envoy configs to V2 (envoyproxy#2957)
  Add timestamp to HealthCheckEvent definition (envoyproxy#4119)
  ...

Signed-off-by: Snow Pettersen <snowp@squareup.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.

4 participants