From b483a8e4e4d3d5347f4a8503031c47b300a5a41b Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 30 May 2022 23:20:41 +0200 Subject: [PATCH] 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. --- src/server/request_context.cpp | 12 ------------ src/server/request_context.h | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/server/request_context.cpp b/src/server/request_context.cpp index c479a6201..53a5cde21 100644 --- a/src/server/request_context.cpp +++ b/src/server/request_context.cpp @@ -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 { diff --git a/src/server/request_context.h b/src/server/request_context.h index 6172bcdf0..6fc7a6a35 100644 --- a/src/server/request_context.h +++ b/src/server/request_context.h @@ -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 + 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;