Add few more utility functions for address and http proto's.#2504
Add few more utility functions for address and http proto's.#2504htuch merged 8 commits intoenvoyproxy:masterfrom colabsaumoh:ext-auth-review-generics
Conversation
Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
mattklein123
left a comment
There was a problem hiding this comment.
few quick comments, thanks
| return result; | ||
| } | ||
|
|
||
| void Utility::addressToProtobufAddress(const Address::Instance& address, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
added tests and consolidated. thanks.
include/envoy/http/header_map.h
Outdated
| /** | ||
| * @return a std::string. | ||
| */ | ||
| std::string getString() const { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
include/envoy/http/protocol.h
Outdated
| enum class Protocol { Http10, Http11, Http2 }; | ||
| const size_t NumProtocols = 3; | ||
|
|
||
| inline std::string getProtocolString(const Protocol& p) { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
consolidated. Thanks.
Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
alyssawilk
left a comment
There was a problem hiding this comment.
nice change! 2 nits from my end.
include/envoy/http/protocol.h
Outdated
| return Http11String; | ||
| case Protocol::Http2: | ||
| return Http2String; | ||
| default: |
There was a problem hiding this comment.
Mild preference for no default - I'd rather have a compile fail if we add a new Protocol and forget to update this function.
There was a problem hiding this comment.
+1 just return directly and avoid default. Add NOT_REACHED at end of function if necessary.
| envoy::api::v2::Address proto_address; | ||
| Address::Ipv4Instance address("127.0.0.1"); | ||
| Utility::addressToProtobufAddress(address, proto_address); | ||
| EXPECT_EQ(true, proto_address.has_socket_address()); |
There was a problem hiding this comment.
For completeness, mind checking the value and port here, and adding a test case for pipe?
include/envoy/http/protocol.h
Outdated
| const size_t NumProtocols = 3; | ||
|
|
||
| static const std::string DefaultString = ""; | ||
| static const std::string Http10String = "HTTP/1.0"; |
There was a problem hiding this comment.
Static non-POD is not allowed in the Envoy style, see https://github.com/envoyproxy/envoy/blob/master/STYLE.md. This could probably just be const char DefaultString = "" etc.
There was a problem hiding this comment.
We could also put these in a struct in headers.h
I was wavering on asking that anyway - they're not so much headers as "part of the firstline" but it's where I'd look for predefined header-type strings.
There was a problem hiding this comment.
IMO we should continue to return string references for perf reasons. I still think that the non-POD rule for std::string is a little silly, but, the rules are the rules. I would just use the constant class pattern we use elsewhere like in Http::Headers.
There was a problem hiding this comment.
@mattklein123 i think you are referring to https://github.com/envoyproxy/envoy/blob/master/source/common/http/headers.h
if so then i can certainly adopt that patter here as well.
@alyssawilk is it ok if i keep the new constant class here?
There was a problem hiding this comment.
Either way is fine with me
There was a problem hiding this comment.
@mattklein123 @alyssawilk Last push addresses this. Adding NOT_REACHED in this file causes a circular dependency so i added a abort(). If that is not what we want then I can move both constants and the getProtocolString to the common/http/headers.h file.
please let me know if that would be preferable.
There was a problem hiding this comment.
I would recommend moving into common and using NOT_REACHED. You can either put in headers.h or feel free to just put in Http::Utility
There was a problem hiding this comment.
cool. moved. please review when u folks get a chance. thanks
include/envoy/http/protocol.h
Outdated
| static const std::string Http11String = "HTTP/1.1"; | ||
| static const std::string Http2String = "HTTP/2"; | ||
|
|
||
| inline const std::string& getProtocolString(const Protocol& p) { |
There was a problem hiding this comment.
Protocol should be passed by value: Protocol p
include/envoy/http/protocol.h
Outdated
| const size_t NumProtocols = 3; | ||
|
|
||
| static const std::string DefaultString = ""; | ||
| static const std::string Http10String = "HTTP/1.0"; |
There was a problem hiding this comment.
IMO we should continue to return string references for perf reasons. I still think that the non-POD rule for std::string is a little silly, but, the rules are the rules. I would just use the constant class pattern we use elsewhere like in Http::Headers.
include/envoy/http/protocol.h
Outdated
| return Http11String; | ||
| case Protocol::Http2: | ||
| return Http2String; | ||
| default: |
There was a problem hiding this comment.
+1 just return directly and avoid default. Add NOT_REACHED at end of function if necessary.
Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
alyssawilk
left a comment
There was a problem hiding this comment.
Looking good - just two nits from me otherwise LGTM
include/envoy/http/protocol.h
Outdated
| @@ -1,4 +1,5 @@ | |||
| #pragma once | |||
| #include <string> | |||
There was a problem hiding this comment.
Can this include be removed?
| * @param protocol for which to return the string representation. | ||
| * @return string representation of the protocol. | ||
| */ | ||
| static const std::string& getProtocolString(const Protocol p); |
There was a problem hiding this comment.
By docs comments I think this should be named "protocol" rather than "p"
There was a problem hiding this comment.
oops. fixed this and the other comment as well.
Merged master also, hopefully that will help with the macos build. fingers crossed.
Thanks for the quick review.
|
Also I'm not quite sure what's with the macos build - I don't recall seeing this error mode on other PRs. Could you try merging with master and take a look if that doesn't fix it? |
Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
…enerics Signed-off-by: Saurabh Mohan <saurabh+github@tigera.io>
These changes are prerequisite for envoyproxy/envoy-mobile#1549 Signed-off-by: Chidera Olibie <colibie@google.com> Signed-off-by: JP Simard <jp@jpsim.com>
These changes are prerequisite for envoyproxy/envoy-mobile#1549 Signed-off-by: Chidera Olibie <colibie@google.com> Signed-off-by: JP Simard <jp@jpsim.com>
Title
Add a few utility functions to the
http/protocolandhttp_header_map.hfilesAddress::Instanceinto it's protobuf representationTesting
I have tested and used these new functions in the PR #2415
added a ut for the http changes.
Risk
Low: like really low.