nghttpx: Use StringRef for string parameters in match_downstream_addr_group

This commit is contained in:
Tatsuhiro Tsujikawa 2016-02-14 20:48:06 +09:00
parent 93eabc642b
commit 49fa914db5
5 changed files with 18 additions and 18 deletions

View File

@ -681,16 +681,19 @@ ClientHandler::get_downstream_connection(Downstream *downstream) {
} else {
auto &router = get_config()->router;
if (!req.authority.empty()) {
group = match_downstream_addr_group(router, req.authority, req.path,
groups, catch_all);
group =
match_downstream_addr_group(router, StringRef{req.authority},
StringRef{req.path}, groups, catch_all);
} else {
auto h = req.fs.header(http2::HD_HOST);
if (h) {
group = match_downstream_addr_group(router, h->value, req.path, groups,
catch_all);
group =
match_downstream_addr_group(router, StringRef{h->value},
StringRef{req.path}, groups, catch_all);
} else {
group = match_downstream_addr_group(router, "", req.path, groups,
catch_all);
group =
match_downstream_addr_group(router, StringRef::from_lit(""),
StringRef{req.path}, groups, catch_all);
}
}
}

View File

@ -2504,7 +2504,7 @@ int int_syslog_facility(const char *strfacility) {
namespace {
size_t match_downstream_addr_group_host(
const Router &router, const std::string &host, const StringRef &path,
const Router &router, const StringRef &host, const StringRef &path,
const std::vector<DownstreamAddrGroup> &groups, size_t catch_all) {
if (path.empty() || path[0] != '/') {
auto group = router.match(host, StringRef::from_lit("/"));
@ -2548,11 +2548,9 @@ size_t match_downstream_addr_group_host(
}
} // namespace
size_t
match_downstream_addr_group(const Router &router, const std::string &hostport,
const std::string &raw_path,
const std::vector<DownstreamAddrGroup> &groups,
size_t catch_all) {
size_t match_downstream_addr_group(
const Router &router, const StringRef &hostport, const StringRef &raw_path,
const std::vector<DownstreamAddrGroup> &groups, size_t catch_all) {
if (std::find(std::begin(hostport), std::end(hostport), '/') !=
std::end(hostport)) {
// We use '/' specially, and if '/' is included in host, it breaks
@ -2589,7 +2587,7 @@ match_downstream_addr_group(const Router &router, const std::string &hostport,
}
util::inp_strlower(host);
return match_downstream_addr_group_host(router, host, path, groups,
return match_downstream_addr_group_host(router, StringRef{host}, path, groups,
catch_all);
}

View File

@ -652,7 +652,7 @@ read_tls_ticket_key_file(const std::vector<std::string> &files,
// group. The catch-all group index is given in |catch_all|. All
// patterns are given in |groups|.
size_t match_downstream_addr_group(
const Router &router, const std::string &hostport, const std::string &path,
const Router &router, const StringRef &hostport, const StringRef &path,
const std::vector<DownstreamAddrGroup> &groups, size_t catch_all);
} // namespace shrpx

View File

@ -259,12 +259,11 @@ const RNode *match_partial(const RNode *node, size_t offset, const char *first,
}
} // namespace
ssize_t Router::match(const std::string &host, const StringRef &path) const {
ssize_t Router::match(const StringRef &host, const StringRef &path) const {
const RNode *node;
size_t offset;
node =
match_complete(&offset, &root_, host.c_str(), host.c_str() + host.size());
node = match_complete(&offset, &root_, std::begin(host), std::end(host));
if (node == nullptr) {
return -1;
}

View File

@ -58,7 +58,7 @@ public:
// Adds route |pattern| with its |index|.
bool add_route(const StringRef &pattern, size_t index);
// Returns the matched index of pattern. -1 if there is no match.
ssize_t match(const std::string &host, const StringRef &path) const;
ssize_t match(const StringRef &host, const StringRef &path) const;
void add_node(RNode *node, const char *pattern, size_t patlen, size_t index);