Skip to content

Commit b930bbe

Browse files
committed
Remove system_query_parameter_names requirements from Method
1 parent d91a0fa commit b930bbe

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/path_matcher.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class PathMatcher {
7777
Method method;
7878
std::vector<HttpTemplate::Variable> variables;
7979
std::string body_field_path;
80+
std::set<std::string> system_query_parameter_names;
8081
};
8182
// The info associated with each method. The path matcher nodes
8283
// will hold pointers to MethodData objects in this vector.
@@ -104,8 +105,12 @@ class PathMatcherBuilder {
104105
// Registrations are one-to-one. If this function is called more than once, it
105106
// replaces the existing method. Only the last registered method is stored.
106107
// Return false if path is an invalid http template.
107-
bool Register(std::string http_method, std::string path,
108-
std::string body_field_path, Method method);
108+
bool Register(const std::string& http_method, const std::string& path,
109+
const std::string& body_field_path,
110+
const std::set<std::string>& system_query_parameter_names,
111+
Method method);
112+
bool Register(const std::string& http_method, const std::string& path,
113+
const std::string& body_field_path, Method method);
109114

110115
// Returns a unique_ptr to a thread safe PathMatcher that contains all
111116
// registered path-WrapperGraph pairs. Note the PathMatchBuilder instance
@@ -412,7 +417,7 @@ Method PathMatcher<Method>::Lookup(
412417
variable_bindings->clear();
413418
ExtractBindingsFromPath(method_data->variables, parts, variable_bindings);
414419
ExtractBindingsFromQueryParameters(
415-
query_params, method_data->method->system_query_parameter_names(),
420+
query_params, method_data->system_query_parameter_names,
416421
variable_bindings);
417422
}
418423
if (body_field_path != nullptr) {
@@ -468,9 +473,10 @@ void PathMatcherBuilder<Method>::InsertPathToNode(
468473
// This wrapper converts the |http_rule| into a HttpTemplate. Then, inserts the
469474
// template into the trie.
470475
template <class Method>
471-
bool PathMatcherBuilder<Method>::Register(std::string http_method,
472-
std::string http_template,
473-
std::string body_field_path,
476+
bool PathMatcherBuilder<Method>::Register(const std::string& http_method,
477+
const std::string& http_template,
478+
const std::string& body_field_path,
479+
const std::set<std::string>& system_query_parameter_names,
474480
Method method) {
475481
std::unique_ptr<HttpTemplate> ht(HttpTemplate::Parse(http_template));
476482
if (nullptr == ht) {
@@ -485,7 +491,8 @@ bool PathMatcherBuilder<Method>::Register(std::string http_method,
485491
auto method_data = std::unique_ptr<MethodData>(new MethodData());
486492
method_data->method = method;
487493
method_data->variables = std::move(ht->Variables());
488-
method_data->body_field_path = std::move(body_field_path);
494+
method_data->body_field_path = body_field_path;
495+
method_data->system_query_parameter_names = system_query_parameter_names;
489496

490497
InsertPathToNode(path_info, method_data.get(), http_method, true,
491498
root_ptr_.get());
@@ -494,6 +501,14 @@ bool PathMatcherBuilder<Method>::Register(std::string http_method,
494501
return true;
495502
}
496503

504+
template <class Method>
505+
bool PathMatcherBuilder<Method>::Register(const std::string& http_method,
506+
const std::string& http_template,
507+
const std::string& body_field_path,
508+
Method method) {
509+
return Register(http_method, http_template, body_field_path, {}, method);
510+
}
511+
497512
} // namespace transcoding
498513
} // namespace grpc
499514
} // namespace google

src/path_matcher_test.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ struct Binding {
4848
typedef std::vector<Binding> Bindings;
4949
typedef std::vector<std::string> FieldPath;
5050
class MethodInfo {
51-
public:
52-
MOCK_CONST_METHOD0(system_query_parameter_names,
53-
const std::set<std::string>&());
5451
};
5552

5653
bool operator==(const Binding& b1, const Binding& b2) {
@@ -92,8 +89,6 @@ class PathMatcherTest : public ::testing::Test {
9289
std::string http_template,
9390
std::string body_field_path) {
9491
auto method = new MethodInfo();
95-
ON_CALL(*method, system_query_parameter_names())
96-
.WillByDefault(ReturnRef(empty_set_));
9792
if (!builder_.Register(http_method, http_template, body_field_path,
9893
method)) {
9994
delete method;
@@ -107,9 +102,7 @@ class PathMatcherTest : public ::testing::Test {
107102
std::string http_method, std::string http_template,
108103
const std::set<std::string>* system_params) {
109104
auto method = new MethodInfo();
110-
ON_CALL(*method, system_query_parameter_names())
111-
.WillByDefault(ReturnRef(*system_params));
112-
if (!builder_.Register(http_method, http_template, std::string(), method)) {
105+
if (!builder_.Register(http_method, http_template, std::string(), *system_params, method)) {
113106
delete method;
114107
return nullptr;
115108
}

0 commit comments

Comments
 (0)