@@ -369,7 +369,8 @@ void ExtractBindingsFromQueryParameters(
369
369
// - Strips off query string: "/a?foo=bar" --> "/a"
370
370
// - Collapses extra slashes: "///" --> "/"
371
371
std::vector<std::string> ExtractRequestParts (
372
- std::string path, const std::unordered_set<std::string>& custom_verbs) {
372
+ std::string path, const std::unordered_set<std::string>& custom_verbs,
373
+ std::string& verb) {
373
374
// Remove query parameters.
374
375
path = path.substr (0 , path.find_first_of (' ?' ));
375
376
@@ -378,11 +379,11 @@ std::vector<std::string> ExtractRequestParts(
378
379
std::size_t last_colon_pos = path.find_last_of (' :' );
379
380
std::size_t last_slash_pos = path.find_last_of (' /' );
380
381
if (last_colon_pos != std::string::npos && last_colon_pos > last_slash_pos) {
381
- std::string verb = path.substr (last_colon_pos + 1 );
382
+ std::string tmp_verb = path.substr (last_colon_pos + 1 );
382
383
// only verb in the configured custom verbs, treat it as verb
383
- // replace ":" with / as a separate segment.
384
- if (custom_verbs. find ( verb) != custom_verbs. end ()) {
385
- path[last_colon_pos] = ' / ' ;
384
+ if (custom_verbs. find (tmp_verb) != custom_verbs. end ()) {
385
+ verb = tmp_verb;
386
+ path = path. substr ( 0 , last_colon_pos) ;
386
387
}
387
388
}
388
389
@@ -412,9 +413,6 @@ PathMatcherNode::PathInfo TransformHttpTemplate(const HttpTemplate& ht) {
412
413
for (const std::string& part : ht.segments ()) {
413
414
builder.AppendLiteralNode (part);
414
415
}
415
- if (!ht.verb ().empty ()) {
416
- builder.AppendLiteralNode (ht.verb ());
417
- }
418
416
419
417
return builder.Build ();
420
418
}
@@ -443,8 +441,9 @@ Method PathMatcher<Method>::Lookup(
443
441
const std::string& query_params,
444
442
std::vector<VariableBinding>* variable_bindings,
445
443
std::string* body_field_path) const {
444
+ std::string verb;
446
445
const std::vector<std::string> parts =
447
- ExtractRequestParts (path, custom_verbs_);
446
+ ExtractRequestParts (path, custom_verbs_, verb );
448
447
449
448
// If service_name has not been registered to ESP and strict_service_matching_
450
449
// is set to false, tries to lookup the method in all registered services.
@@ -453,7 +452,7 @@ Method PathMatcher<Method>::Lookup(
453
452
}
454
453
455
454
PathMatcherLookupResult lookup_result =
456
- LookupInPathMatcherNode (*root_ptr_, parts, http_method);
455
+ LookupInPathMatcherNode (*root_ptr_, parts, http_method + verb );
457
456
// Return nullptr if nothing is found or the result is marked for duplication.
458
457
if (lookup_result.data == nullptr || lookup_result.is_multiple ) {
459
458
return nullptr ;
@@ -477,8 +476,9 @@ Method PathMatcher<Method>::Lookup(
477
476
template <class Method >
478
477
Method PathMatcher<Method>::Lookup(const std::string& http_method,
479
478
const std::string& path) const {
479
+ std::string verb;
480
480
const std::vector<std::string> parts =
481
- ExtractRequestParts (path, custom_verbs_);
481
+ ExtractRequestParts (path, custom_verbs_, verb );
482
482
483
483
// If service_name has not been registered to ESP and strict_service_matching_
484
484
// is set to false, tries to lookup the method in all registered services.
@@ -487,7 +487,7 @@ Method PathMatcher<Method>::Lookup(const std::string& http_method,
487
487
}
488
488
489
489
PathMatcherLookupResult lookup_result =
490
- LookupInPathMatcherNode (*root_ptr_, parts, http_method);
490
+ LookupInPathMatcherNode (*root_ptr_, parts, http_method + verb );
491
491
// Return nullptr if nothing is found or the result is marked for duplication.
492
492
if (lookup_result.data == nullptr || lookup_result.is_multiple ) {
493
493
return nullptr ;
@@ -540,7 +540,7 @@ bool PathMatcherBuilder<Method>::Register(
540
540
method_data->body_field_path = body_field_path;
541
541
method_data->system_query_parameter_names = system_query_parameter_names;
542
542
543
- InsertPathToNode (path_info, method_data.get (), http_method, true ,
543
+ InsertPathToNode (path_info, method_data.get (), http_method + ht-> verb () , true ,
544
544
root_ptr_.get ());
545
545
// Add the method_data to the methods_ vector for cleanup
546
546
methods_.emplace_back (std::move (method_data));
0 commit comments