From 2f820b81c424273547a35edb066bb163120ebafe Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Mon, 4 Dec 2023 11:49:07 +0800 Subject: [PATCH] Enhancements Fix request arguments to alias are not passed to redirect location (#681). Fix crash if name argument is missing in getProfile interface. Fix bad webGet retry logic. --- src/handler/interfaces.cpp | 4 ++-- src/handler/webget.cpp | 2 +- src/server/webserver_httplib.cpp | 14 +++++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/handler/interfaces.cpp b/src/handler/interfaces.cpp index 18f483280..418d58930 100644 --- a/src/handler/interfaces.cpp +++ b/src/handler/interfaces.cpp @@ -1162,13 +1162,13 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS) std::string name = urlDecode(getUrlArg(argument, "name")), token = urlDecode(getUrlArg(argument, "token")); string_array profiles = split(name, "|"); - name = profiles[0]; - if(token.empty() || name.empty()) + if(token.empty() || profiles.empty()) { *status_code = 403; return "Forbidden"; } std::string profile_content; + name = profiles[0]; /*if(vfs::vfs_exist(name)) { profile_content = vfs::vfs_get(name); diff --git a/src/handler/webget.cpp b/src/handler/webget.cpp index c82003ad3..c24fe98ac 100644 --- a/src/handler/webget.cpp +++ b/src/handler/webget.cpp @@ -252,7 +252,7 @@ static int curlGet(const FetchArgument &argument, FetchResult &result) while(true) { retVal = curl_easy_perform(curl_handle); - if(retVal == CURLE_OK || max_fails >= fail_count) + if(retVal == CURLE_OK || max_fails <= fail_count) break; else fail_count++; diff --git a/src/server/webserver_httplib.cpp b/src/server/webserver_httplib.cpp index d9d375470..4756b8e56 100644 --- a/src/server/webserver_httplib.cpp +++ b/src/server/webserver_httplib.cpp @@ -155,7 +155,19 @@ int WebServer::start_web_server_multi(listener_args *args) for (auto &x : redirect_map) { server.Get(x.first, [x](const httplib::Request &req, httplib::Response &res) { - res.set_redirect(x.second); + auto arguments = req.params; + auto query = x.second; + auto pos = query.find('?'); + query += pos == std::string::npos ? '?' : '&'; + for (auto &p: arguments) + { + query += p.first + "=" + urlEncode(p.second) + "&"; + } + if (!query.empty()) + { + query.pop_back(); + } + res.set_redirect(query); }); } server.set_exception_handler([](const httplib::Request &req, httplib::Response &res, const std::exception_ptr &e)