Copilot commented on code in PR #3767:
URL: https://github.com/apache/brpc/pull/3767#discussion_r4658408313


##########
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:
   This early return runs before `BuildAcceptor()` validates the whitelist 
names. With the default `has_builtin_services=true`, a configuration such as 
`enabled_protocols = "not_a_protocol"` reports only the HTTP-only 
misconfiguration; following the suggested fix by adding `http` still fails 
afterward with an unknown-protocol error. Validate unknown names before this 
feature check, or include them in the same diagnostic, so the error is 
actionable for invalid whitelists.



-- 
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]

Reply via email to