wwbmmm commented on code in PR #3767:
URL: https://github.com/apache/brpc/pull/3767#discussion_r4658555121
##########
src/brpc/server.cpp:
##########
@@ -686,15 +686,72 @@ int Server::AddBuiltinServices() {
return 0;
}
-BUTIL_FORCE_INLINE bool is_http_protocol(const char* name) {
- if (name[0] != 'h') {
- return false;
+BUTIL_FORCE_INLINE bool is_rdma_handshake_protocol(const char* name) {
+ return strcmp(name, "rdma_handshake") == 0;
+}
+
+// Restful services are served through http/h2 requests. Empty maps may be
+// left by RemoveService(), so check the number of mappings instead of the
+// existence of the map.
+static bool HasRestfulServices(const Server::ServiceMap& services,
+ const RestfulMap* global_restful_map) {
+ if (global_restful_map != nullptr && global_restful_map->size() != 0) {
+ return true;
+ }
+ for (Server::ServiceMap::const_iterator it = services.begin();
+ it != services.end(); ++it) {
+ if (it->second.restful_map != nullptr &&
+ it->second.restful_map->size() != 0) {
+ return true;
+ }
}
- return strcmp(name, "http") == 0 || strcmp(name, "h2") == 0;
+ return false;
}
-BUTIL_FORCE_INLINE bool is_rdma_handshake_protocol(const char* name) {
- return strcmp(name, "rdma_handshake") == 0;
+static std::string JoinWithAnd(const std::vector<std::string>& strs) {
+ std::string out;
+ for (size_t i = 0; i < strs.size(); ++i) {
+ if (i != 0) {
+ out.append(i + 1 == strs.size() ? " and " : ", ");
+ }
+ out.append(strs[i]);
+ }
+ return out;
+}
+
+int Server::ValidateHttpOnlyFeatures() const {
+ std::unordered_set<std::string> whitelist;
+ for (butil::StringSplitter sp(_options.enabled_protocols.c_str(), ' ');
+ sp; ++sp) {
+ whitelist.insert(std::string(sp.field(), sp.length()));
+ }
+ if (whitelist.empty() || whitelist.count("http") != 0 ||
+ whitelist.count("h2") != 0) {
+ return 0;
Review Comment:
[replied by brpc-oncall robot] Fixed: the whitelist names are now validated
first in `ValidateEnabledProtocols()` (called before builtin services are
added), and only then is the http/h2 requirement of
builtin/restful/`http_master_service` checked. `BuildAcceptor()` just filters
protocols by the whitelist. `invalid_protocol_in_enabled_protocols` now also
asserts that a failed `Start()` with `enabled_protocols="hehe baidu_std"` added
no builtin services, so the unknown-name error is reported instead of being
masked.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]