Make the request_context be able to generate a querystring for a subset.

The request_context can now take a filter to select arguments to
keep in the query string.
This commit is contained in:
Matthieu Gautier 2022-05-30 23:20:41 +02:00
parent e2ab7fd62e
commit b483a8e4e4
2 changed files with 20 additions and 13 deletions

View File

@ -189,18 +189,6 @@ std::string RequestContext::get_header(const std::string& name) const {
return headers.at(lcAll(name));
}
std::string RequestContext::get_query() const {
std::string q;
const char* sep = "";
for ( const auto& a : arguments ) {
for (const auto& v: a.second) {
q += sep + a.first + '=' + v;
sep = "&";
}
}
return q;
}
std::string RequestContext::get_user_language() const
{
try {

View File

@ -91,7 +91,26 @@ class RequestContext {
std::string get_url() const;
std::string get_url_part(int part) const;
std::string get_full_url() const;
std::string get_query() const;
std::string get_query() const {
return get_query([](const std::string& key) {return true;});
}
template<class F>
std::string get_query(F filter) const {
std::string q;
const char* sep = "";
for ( const auto& a : arguments ) {
if (!filter(a.first)) {
continue;
}
for (const auto& v: a.second) {
q += sep + a.first + '=' + v;
sep = "&";
}
}
return q;
}
ByteRange get_range() const;