@@ -332,7 +332,9 @@ void ExtractBindingsFromQueryParameters(
332
332
//
333
333
// - Strips off query string: "/a?foo=bar" --> "/a"
334
334
// - 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) {
336
338
// Remove query parameters.
337
339
path = path.substr (0 , path.find_first_of (' ?' ));
338
340
@@ -341,7 +343,12 @@ std::vector<std::string> ExtractRequestParts(std::string path) {
341
343
std::size_t last_colon_pos = path.find_last_of (' :' );
342
344
std::size_t last_slash_pos = path.find_last_of (' /' );
343
345
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
+ }
345
352
}
346
353
347
354
std::vector<std::string> result;
@@ -400,7 +407,7 @@ Method PathMatcher<Method>::Lookup(
400
407
const std::string& query_params,
401
408
std::vector<VariableBinding>* variable_bindings,
402
409
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_ );
404
411
405
412
// If service_name has not been registered to ESP and strict_service_matching_
406
413
// is set to false, tries to lookup the method in all registered services.
@@ -432,7 +439,7 @@ Method PathMatcher<Method>::Lookup(
432
439
template <class Method >
433
440
Method PathMatcher<Method>::Lookup(const std::string& http_method,
434
441
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_ );
436
443
437
444
// If service_name has not been registered to ESP and strict_service_matching_
438
445
// is set to false, tries to lookup the method in all registered services.
@@ -500,6 +507,9 @@ bool PathMatcherBuilder<Method>::Register(
500
507
root_ptr_.get ());
501
508
// Add the method_data to the methods_ vector for cleanup
502
509
methods_.emplace_back (std::move (method_data));
510
+ if (!ht->verb ().empty ()) {
511
+ custom_verbs_.insert (ht->verb ());
512
+ }
503
513
return true ;
504
514
}
505
515
0 commit comments