diff --git a/server/WebApi.h b/server/WebApi.h index cc0e95fd..79fea18f 100755 --- a/server/WebApi.h +++ b/server/WebApi.h @@ -78,42 +78,45 @@ public: using ApiArgsType = std::map; -template -std::string getValue(Args &args, const First &first) { - return args[first]; +template +std::string getValue(Args &args, const Key &key) { + auto it = args.find(key); + if (it == args.end()) { + return ""; + } + return it->second; } -template -std::string getValue(Json::Value &args, const First &first) { - return args[first].asString(); +template +std::string getValue(Json::Value &args, const Key &key) { + auto it = args.find(key); + if (it == args.end()) { + return ""; + } + return it->second.asString(); } -template -std::string getValue(std::string &args, const First &first) { +template +std::string getValue(std::string &args, const Key &key) { return ""; } -template -std::string getValue(const mediakit::Parser &parser, const First &first) { - auto ret = parser.getUrlArgs()[first]; +template +std::string getValue(const mediakit::Parser &parser, const Key &key) { + auto ret = getValue(parser.getUrlArgs(), key); if (!ret.empty()) { return ret; } - return parser.getHeader()[first]; + return getValue(parser.getHeader(), key); } -template -std::string getValue(mediakit::Parser &parser, const First &first) { - return getValue((const mediakit::Parser &) parser, first); -} - -template -std::string getValue(const mediakit::Parser &parser, Args &args, const First &first) { - auto ret = getValue(args, first); +template +std::string getValue(const mediakit::Parser &parser, Args &args, const Key &key) { + auto ret = getValue(args, key); if (!ret.empty()) { return ret; } - return getValue(parser, first); + return getValue(parser, key); } template @@ -177,14 +180,14 @@ void api_regist(const std::string &api_path, const std::function &func); -template -bool checkArgs(Args &args, const First &first) { - return !args[first].empty(); +template +bool checkArgs(Args &args, const Key &key) { + return !args[key].empty(); } -template -bool checkArgs(Args &args, const First &first, const KeyTypes &...keys) { - return checkArgs(args, first) && checkArgs(args, keys...); +template +bool checkArgs(Args &args, const Key &key, const KeyTypes &...keys) { + return checkArgs(args, key) && checkArgs(args, keys...); } // 检查http url中或body中或http header参数是否为空的宏 [AUTO-TRANSLATED:9de001a4]