| 1086 | } |
| 1087 | |
| 1088 | inline const Server::MethodProperty* |
| 1089 | FindMethodPropertyByURIImpl(const std::string& uri_path, const Server* server, |
| 1090 | std::string* unresolved_path) { |
| 1091 | ServerPrivateAccessor wrapper(server); |
| 1092 | butil::StringSplitter splitter(uri_path.c_str(), '/'); |
| 1093 | // Show index page for empty URI |
| 1094 | if (NULL == splitter) { |
| 1095 | return wrapper.FindMethodPropertyByFullName( |
| 1096 | IndexService::descriptor()->full_name(), common->DEFAULT_METHOD); |
| 1097 | } |
| 1098 | butil::StringPiece service_name(splitter.field(), splitter.length()); |
| 1099 | const bool full_service_name = |
| 1100 | (service_name.find('.') != butil::StringPiece::npos); |
| 1101 | const Server::ServiceProperty* const sp = |
| 1102 | (full_service_name ? |
| 1103 | wrapper.FindServicePropertyByFullName(service_name) : |
| 1104 | wrapper.FindServicePropertyByName(service_name)); |
| 1105 | if (NULL == sp) { |
| 1106 | // normal for urls matching _global_restful_map |
| 1107 | return NULL; |
| 1108 | } |
| 1109 | // Find restful methods by uri. |
| 1110 | if (sp->restful_map) { |
| 1111 | ++splitter; |
| 1112 | butil::StringPiece left_path; |
| 1113 | if (splitter) { |
| 1114 | // The -1 is for including /, always safe because of ++splitter |
| 1115 | left_path.set(splitter.field() - 1, uri_path.c_str() + |
| 1116 | uri_path.size() - splitter.field() + 1); |
| 1117 | } |
| 1118 | return sp->restful_map->FindMethodProperty(left_path, unresolved_path); |
| 1119 | } |
| 1120 | if (!full_service_name) { |
| 1121 | // Change to service's fullname. |
| 1122 | service_name = sp->service->GetDescriptor()->full_name(); |
| 1123 | } |
| 1124 | |
| 1125 | // Regard URI as [service_name]/[method_name] |
| 1126 | const Server::MethodProperty* mp = NULL; |
| 1127 | butil::StringPiece method_name; |
| 1128 | if (++splitter != NULL) { |
| 1129 | method_name.set(splitter.field(), splitter.length()); |
| 1130 | // Copy splitter rather than modifying it directly since it's used |
| 1131 | // in later branches. |
| 1132 | mp = wrapper.FindMethodPropertyByFullName(service_name, method_name); |
| 1133 | if (mp) { |
| 1134 | ++splitter; // skip method name |
| 1135 | FillUnresolvedPath(unresolved_path, uri_path, splitter); |
| 1136 | return mp; |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | // Try [service_name]/default_method |
| 1141 | mp = wrapper.FindMethodPropertyByFullName(service_name, common->DEFAULT_METHOD); |
| 1142 | if (mp) { |
| 1143 | FillUnresolvedPath(unresolved_path, uri_path, splitter); |
| 1144 | return mp; |
| 1145 | } |
no test coverage detected