From 49fa914db5cbf74708e025f9aeae74f9a79f2ab1 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 14 Feb 2016 20:48:06 +0900 Subject: [PATCH] nghttpx: Use StringRef for string parameters in match_downstream_addr_group --- src/shrpx_client_handler.cc | 15 +++++++++------ src/shrpx_config.cc | 12 +++++------- src/shrpx_config.h | 2 +- src/shrpx_router.cc | 5 ++--- src/shrpx_router.h | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index fa814dd9..4d063647 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -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); } } } diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index a5d9f534..5e6236c3 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -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 &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 &groups, - size_t catch_all) { +size_t match_downstream_addr_group( + const Router &router, const StringRef &hostport, const StringRef &raw_path, + const std::vector &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); } diff --git a/src/shrpx_config.h b/src/shrpx_config.h index e024317a..b81f8e1d 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -652,7 +652,7 @@ read_tls_ticket_key_file(const std::vector &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 &groups, size_t catch_all); } // namespace shrpx diff --git a/src/shrpx_router.cc b/src/shrpx_router.cc index 2975c3e9..4c88283f 100644 --- a/src/shrpx_router.cc +++ b/src/shrpx_router.cc @@ -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; } diff --git a/src/shrpx_router.h b/src/shrpx_router.h index 5f70b212..ece0e276 100644 --- a/src/shrpx_router.h +++ b/src/shrpx_router.h @@ -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);