From 812cb5bc3d873e45dd7505ec25b38f3981c7cfbe Mon Sep 17 00:00:00 2001 From: Wang Gao <80475837@qq.com> Date: Wed, 3 Jun 2020 07:05:04 +0800 Subject: [PATCH] fix get value function (#509) --- httplib.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/httplib.h b/httplib.h index c6439b8..8561514 100644 --- a/httplib.h +++ b/httplib.h @@ -2268,9 +2268,10 @@ inline bool has_header(const Headers &headers, const char *key) { inline const char *get_header_value(const Headers &headers, const char *key, size_t id = 0, const char *def = nullptr) { - auto it = headers.find(key); - std::advance(it, static_cast(id)); - if (it != headers.end()) { return it->second.c_str(); } + auto itRange = headers.equal_range(key); + auto it = itRange.first; + std::advance(it, static_cast(id)); + if(it != itRange.second) { return it->second.c_str(); } return def; } @@ -3291,9 +3292,10 @@ inline bool Request::has_param(const char *key) const { } inline std::string Request::get_param_value(const char *key, size_t id) const { - auto it = params.find(key); + auto itRange = params.equal_range(key); + auto it = itRange.first; std::advance(it, static_cast(id)); - if (it != params.end()) { return it->second; } + if(it != itRange.second) { return it->second; } return std::string(); }