[http] fix query detection, addresshelper processing, update tests

Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
R4SAS 2023-02-14 18:51:14 +00:00
parent 4156900fb5
commit 77142e59ee
No known key found for this signature in database
GPG key ID: 66F6C87B98EBCFE2
4 changed files with 59 additions and 14 deletions

View file

@ -238,9 +238,33 @@ namespace proxy {
std::string value = params["i2paddresshelper"];
len += value.length();
b64 = i2p::http::UrlDecode(value);
// if we need update exists, request formed with update param
if (params["update"] == "true") { len += std::strlen("&update=true"); confirm = true; }
if (pos != 0 && url.query[pos-1] == '&') { pos--; len++; } // if helper is not only one query option
if (params["update"] == "true")
{
len += std::strlen("&update=true");
confirm = true;
}
// if helper is not only one query option and it placed after user's query
if (pos != 0 && url.query[pos-1] == '&')
{
pos--;
len++;
}
// if helper is not only one query option and it placed before user's query
else if (pos == 0 && url.query.length () > len && url.query[len] == '&')
{
// we don't touch the '?' but remove the trailing '&'
len++;
}
else
{
// there is no more query options, resetting hasquery flag
url.hasquery = false;
}
// reset hasquery flag and remove addresshelper from URL
url.query.replace(pos, len, "");
return true;
}