nghttpx: Use StringRef for string parameters in match_downstream_addr_group
This commit is contained in:
parent
93eabc642b
commit
49fa914db5
|
@ -681,16 +681,19 @@ ClientHandler::get_downstream_connection(Downstream *downstream) {
|
||||||
} else {
|
} else {
|
||||||
auto &router = get_config()->router;
|
auto &router = get_config()->router;
|
||||||
if (!req.authority.empty()) {
|
if (!req.authority.empty()) {
|
||||||
group = match_downstream_addr_group(router, req.authority, req.path,
|
group =
|
||||||
groups, catch_all);
|
match_downstream_addr_group(router, StringRef{req.authority},
|
||||||
|
StringRef{req.path}, groups, catch_all);
|
||||||
} else {
|
} else {
|
||||||
auto h = req.fs.header(http2::HD_HOST);
|
auto h = req.fs.header(http2::HD_HOST);
|
||||||
if (h) {
|
if (h) {
|
||||||
group = match_downstream_addr_group(router, h->value, req.path, groups,
|
group =
|
||||||
catch_all);
|
match_downstream_addr_group(router, StringRef{h->value},
|
||||||
|
StringRef{req.path}, groups, catch_all);
|
||||||
} else {
|
} else {
|
||||||
group = match_downstream_addr_group(router, "", req.path, groups,
|
group =
|
||||||
catch_all);
|
match_downstream_addr_group(router, StringRef::from_lit(""),
|
||||||
|
StringRef{req.path}, groups, catch_all);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2504,7 +2504,7 @@ int int_syslog_facility(const char *strfacility) {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
size_t match_downstream_addr_group_host(
|
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) {
|
const std::vector<DownstreamAddrGroup> &groups, size_t catch_all) {
|
||||||
if (path.empty() || path[0] != '/') {
|
if (path.empty() || path[0] != '/') {
|
||||||
auto group = router.match(host, StringRef::from_lit("/"));
|
auto group = router.match(host, StringRef::from_lit("/"));
|
||||||
|
@ -2548,11 +2548,9 @@ size_t match_downstream_addr_group_host(
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
size_t
|
size_t match_downstream_addr_group(
|
||||||
match_downstream_addr_group(const Router &router, const std::string &hostport,
|
const Router &router, const StringRef &hostport, const StringRef &raw_path,
|
||||||
const std::string &raw_path,
|
const std::vector<DownstreamAddrGroup> &groups, size_t catch_all) {
|
||||||
const std::vector<DownstreamAddrGroup> &groups,
|
|
||||||
size_t catch_all) {
|
|
||||||
if (std::find(std::begin(hostport), std::end(hostport), '/') !=
|
if (std::find(std::begin(hostport), std::end(hostport), '/') !=
|
||||||
std::end(hostport)) {
|
std::end(hostport)) {
|
||||||
// We use '/' specially, and if '/' is included in host, it breaks
|
// 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);
|
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);
|
catch_all);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
// group. The catch-all group index is given in |catch_all|. All
|
||||||
// patterns are given in |groups|.
|
// patterns are given in |groups|.
|
||||||
size_t match_downstream_addr_group(
|
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);
|
const std::vector<DownstreamAddrGroup> &groups, size_t catch_all);
|
||||||
|
|
||||||
} // namespace shrpx
|
} // namespace shrpx
|
||||||
|
|
|
@ -259,12 +259,11 @@ const RNode *match_partial(const RNode *node, size_t offset, const char *first,
|
||||||
}
|
}
|
||||||
} // namespace
|
} // 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;
|
const RNode *node;
|
||||||
size_t offset;
|
size_t offset;
|
||||||
|
|
||||||
node =
|
node = match_complete(&offset, &root_, std::begin(host), std::end(host));
|
||||||
match_complete(&offset, &root_, host.c_str(), host.c_str() + host.size());
|
|
||||||
if (node == nullptr) {
|
if (node == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
// Adds route |pattern| with its |index|.
|
// Adds route |pattern| with its |index|.
|
||||||
bool add_route(const StringRef &pattern, size_t index);
|
bool add_route(const StringRef &pattern, size_t index);
|
||||||
// Returns the matched index of pattern. -1 if there is no match.
|
// 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);
|
void add_node(RNode *node, const char *pattern, size_t patlen, size_t index);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue