@@ -332,7 +332,9 @@ void ExtractBindingsFromQueryParameters(
332332//
333333// - Strips off query string: "/a?foo=bar" --> "/a"
334334// - Collapses extra slashes: "///" --> "/"
335- std::vector<std::string> ExtractRequestParts (std::string path) {
335+ std::vector<std::string> ExtractRequestParts (
336+ std::string path,
337+ const std::unordered_set<std::string>& custom_verbs) {
336338 // Remove query parameters.
337339 path = path.substr (0 , path.find_first_of (' ?' ));
338340
@@ -341,7 +343,12 @@ std::vector<std::string> ExtractRequestParts(std::string path) {
341343 std::size_t last_colon_pos = path.find_last_of (' :' );
342344 std::size_t last_slash_pos = path.find_last_of (' /' );
343345 if (last_colon_pos != std::string::npos && last_colon_pos > last_slash_pos) {
344- path[last_colon_pos] = ' /' ;
346+ std::string verb = path.substr (last_colon_pos + 1 );
347+ // only verb in the configured custom verbs, treat it as verb
348+ // replace ":" with / as a separate segment.
349+ if (custom_verbs.find (verb) != custom_verbs.end ()) {
350+ path[last_colon_pos] = ' /' ;
351+ }
345352 }
346353
347354 std::vector<std::string> result;
@@ -400,7 +407,7 @@ Method PathMatcher<Method>::Lookup(
400407 const std::string& query_params,
401408 std::vector<VariableBinding>* variable_bindings,
402409 std::string* body_field_path) const {
403- const std::vector<std::string> parts = ExtractRequestParts (path);
410+ const std::vector<std::string> parts = ExtractRequestParts (path, custom_verbs_ );
404411
405412 // If service_name has not been registered to ESP and strict_service_matching_
406413 // is set to false, tries to lookup the method in all registered services.
@@ -432,7 +439,7 @@ Method PathMatcher<Method>::Lookup(
432439template <class Method >
433440Method PathMatcher<Method>::Lookup(const std::string& http_method,
434441 const std::string& path) const {
435- const std::vector<std::string> parts = ExtractRequestParts (path);
442+ const std::vector<std::string> parts = ExtractRequestParts (path, custom_verbs_ );
436443
437444 // If service_name has not been registered to ESP and strict_service_matching_
438445 // is set to false, tries to lookup the method in all registered services.
@@ -500,6 +507,9 @@ bool PathMatcherBuilder<Method>::Register(
500507 root_ptr_.get ());
501508 // Add the method_data to the methods_ vector for cleanup
502509 methods_.emplace_back (std::move (method_data));
510+ if (!ht->verb ().empty ()) {
511+ custom_verbs_.insert (ht->verb ());
512+ }
503513 return true ;
504514}
505515
0 commit comments