Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tindy2013 committed Dec 4, 2023
1 parent d9ff111 commit 2f820b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/handler/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/handler/webget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
14 changes: 13 additions & 1 deletion src/server/webserver_httplib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2f820b8

Please sign in to comment.