mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-02-27 18:50:52 +08:00
优化http参数获取逻辑
This commit is contained in:
@@ -78,42 +78,45 @@ public:
|
|||||||
|
|
||||||
using ApiArgsType = std::map<std::string, std::string, mediakit::StrCaseCompare>;
|
using ApiArgsType = std::map<std::string, std::string, mediakit::StrCaseCompare>;
|
||||||
|
|
||||||
template<typename Args, typename First>
|
template<typename Args, typename Key>
|
||||||
std::string getValue(Args &args, const First &first) {
|
std::string getValue(Args &args, const Key &key) {
|
||||||
return args[first];
|
auto it = args.find(key);
|
||||||
|
if (it == args.end()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename First>
|
template<typename Key>
|
||||||
std::string getValue(Json::Value &args, const First &first) {
|
std::string getValue(Json::Value &args, const Key &key) {
|
||||||
return args[first].asString();
|
auto it = args.find(key);
|
||||||
|
if (it == args.end()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return it->second.asString();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename First>
|
template<typename Key>
|
||||||
std::string getValue(std::string &args, const First &first) {
|
std::string getValue(std::string &args, const Key &key) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename First>
|
template <typename Key>
|
||||||
std::string getValue(const mediakit::Parser &parser, const First &first) {
|
std::string getValue(const mediakit::Parser &parser, const Key &key) {
|
||||||
auto ret = parser.getUrlArgs()[first];
|
auto ret = getValue(parser.getUrlArgs(), key);
|
||||||
if (!ret.empty()) {
|
if (!ret.empty()) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return parser.getHeader()[first];
|
return getValue(parser.getHeader(), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename First>
|
template<typename Args, typename Key>
|
||||||
std::string getValue(mediakit::Parser &parser, const First &first) {
|
std::string getValue(const mediakit::Parser &parser, Args &args, const Key &key) {
|
||||||
return getValue((const mediakit::Parser &) parser, first);
|
auto ret = getValue(args, key);
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Args, typename First>
|
|
||||||
std::string getValue(const mediakit::Parser &parser, Args &args, const First &first) {
|
|
||||||
auto ret = getValue(args, first);
|
|
||||||
if (!ret.empty()) {
|
if (!ret.empty()) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return getValue(parser, first);
|
return getValue(parser, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Args>
|
template<typename Args>
|
||||||
@@ -177,14 +180,14 @@ void api_regist(const std::string &api_path, const std::function<void(API_ARGS_S
|
|||||||
// Register http request parameters as http original request information asynchronous reply http api
|
// Register http request parameters as http original request information asynchronous reply http api
|
||||||
void api_regist(const std::string &api_path, const std::function<void(API_ARGS_STRING_ASYNC)> &func);
|
void api_regist(const std::string &api_path, const std::function<void(API_ARGS_STRING_ASYNC)> &func);
|
||||||
|
|
||||||
template<typename Args, typename First>
|
template<typename Args, typename Key>
|
||||||
bool checkArgs(Args &args, const First &first) {
|
bool checkArgs(Args &args, const Key &key) {
|
||||||
return !args[first].empty();
|
return !args[key].empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Args, typename First, typename ...KeyTypes>
|
template<typename Args, typename Key, typename ...KeyTypes>
|
||||||
bool checkArgs(Args &args, const First &first, const KeyTypes &...keys) {
|
bool checkArgs(Args &args, const Key &key, const KeyTypes &...keys) {
|
||||||
return checkArgs(args, first) && checkArgs(args, keys...);
|
return checkArgs(args, key) && checkArgs(args, keys...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查http url中或body中或http header参数是否为空的宏 [AUTO-TRANSLATED:9de001a4]
|
// 检查http url中或body中或http header参数是否为空的宏 [AUTO-TRANSLATED:9de001a4]
|
||||||
|
|||||||
Reference in New Issue
Block a user