-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add few more utility functions for address and http proto's. #2504
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
Changes from 1 commit
da62afa
858d842
ab15cc3
a519fb3
57c6f26
e4156e8
49a3570
df0f0bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #pragma once | ||
| #include <string> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this include be removed? |
||
|
|
||
| namespace Envoy { | ||
| namespace Http { | ||
|
|
@@ -10,5 +11,19 @@ namespace Http { | |
| enum class Protocol { Http10, Http11, Http2 }; | ||
| const size_t NumProtocols = 3; | ||
|
|
||
| inline std::string getProtocolString(const Protocol& p) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already implemented here: https://github.com/envoyproxy/envoy/blob/master/source/common/access_log/access_log_formatter.cc#L33 Please consolidate (and use the string in access log formatter to be consistent).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consolidated. Thanks. |
||
| switch (p) { | ||
| case Protocol::Http10: | ||
| return std::string("Http1.0"); | ||
| case Protocol::Http11: | ||
| return std::string("Http1.1"); | ||
| case Protocol::Http2: | ||
| return std::string("Http2"); | ||
| default: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mild preference for no default - I'd rather have a compile fail if we add a new Protocol and forget to update this function.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 just return directly and avoid default. Add NOT_REACHED at end of function if necessary. |
||
| break; | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| } // namespace Http | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -371,5 +371,17 @@ absl::uint128 Utility::flipOrder(const absl::uint128& input) { | |
| return result; | ||
| } | ||
|
|
||
| void Utility::addressToProtobufAddress(const Address::Instance& address, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already implemented here: https://github.com/envoyproxy/envoy/blob/master/source/common/access_log/grpc_access_log_impl.cc#L67 please consolidate Also, a dedicated function like this needs dedicated tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added tests and consolidated. thanks. |
||
| envoy::api::v2::Address& proto_address) { | ||
| if (address.type() == Address::Type::Pipe) { | ||
| proto_address.mutable_pipe()->set_path(address.asString()); | ||
| } else { | ||
| ASSERT(address.type() == Address::Type::Ip); | ||
| auto* socket_address = proto_address.mutable_socket_address(); | ||
| socket_address->set_address(address.ip()->addressAsString()); | ||
| socket_address->set_port_value(address.ip()->port()); | ||
| } | ||
| } | ||
|
|
||
| } // namespace Network | ||
| } // namespace Envoy | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really necessary? Seems pretty superfluous to me, but I don't feel that strongly about it. If it is, I suspect you don't need the if statement and the constructor will do the right thing if you pass a length of 0, but I'm not sure.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the need for it came up in the feedback for pr #2415
it is kind of useful to have it here and not have the user have to convert a
c_str(). thx