diff --git a/src/http/microhttpd_server.cpp b/src/http/microhttpd_server.cpp index 73976ad..ce5e48f 100644 --- a/src/http/microhttpd_server.cpp +++ b/src/http/microhttpd_server.cpp @@ -63,7 +63,7 @@ namespace switch (kind) { case MHD_GET_ARGUMENT_KIND: - request.get.insert({std::string_view(key, key_len), std::string(value, value_len)}); + request.param.insert({ {key, key + key_len}, std::string(value, value_len)}); break; case MHD_HEADER_KIND: if (std::string_view(key, key_len) == "Content-Type") diff --git a/src/http/request.cpp b/src/http/request.cpp index 29cc0e3..7a7fc1d 100644 --- a/src/http/request.cpp +++ b/src/http/request.cpp @@ -24,7 +24,8 @@ using namespace HTTP; Request::Request(Type type, const std::string url, unsigned mimetypes /* = HTTP::MIME::ANY */) : type{type}, url{std::move(url)}, - mimetypes{mimetypes} + mimetypes{mimetypes}, + param{} {} bool Request::operator==(const Request& other) const diff --git a/src/http/request.h b/src/http/request.h index c9ba63a..42b8a9f 100644 --- a/src/http/request.h +++ b/src/http/request.h @@ -38,10 +38,10 @@ namespace HTTP */ using RequestArgs_t = std::vector; using RequestCallback_t = std::function< - std::optional( std::any&, const Request&, RequestArgs_t& )>; + std::optional( std::any&, Request&, RequestArgs_t& )>; using RequestCallbackPair_t = std::pair; - using KeyStrVarMap = std::map; /** @@ -122,7 +122,10 @@ namespace HTTP /** @remark Assuming this wasn't a propagated mimetype (OR mime) */ inline HTTP::MIME::Mimetypes get_mime() const noexcept { return static_cast(mimetypes); } - KeyStrVarMap get; + + /** @brief GET or POST parameters */ + KeyStrVarMap param; + /** @see mime.h */ unsigned mimetypes; diff --git a/src/jsonhelper.cpp b/src/jsonhelper.cpp index e485839..c4caffa 100644 --- a/src/jsonhelper.cpp +++ b/src/jsonhelper.cpp @@ -27,9 +27,14 @@ std::string rjson::to_string(rjson::Document& doc) return buf.GetString(); } -bool try_load_args_from_json(const HTTP::Request& req, - HTTP::RequestArgs_t& arg) +#include +bool try_load_args_from_json(HTTP::Request& req) { - + rjson::Document doc; + doc.Parse(req.data.data()); + for (auto itr = doc.MemberBegin(); itr != doc.MemberEnd(); ++itr) + { + req.param.insert({ itr->name.GetString(), std::string(itr->value.GetString()) }); + } return true; } diff --git a/src/jsonhelper.h b/src/jsonhelper.h index eb8ce9b..4a56903 100644 --- a/src/jsonhelper.h +++ b/src/jsonhelper.h @@ -47,5 +47,4 @@ namespace rjson * @param arg Argument that will get modified (if no exception thrown) * @return true if modified, false if the same. */ -bool try_load_args_from_json(const HTTP::Request& req, - HTTP::RequestArgs_t& arg); +bool try_load_args_from_json(HTTP::Request& req); diff --git a/src/protocol/masto-api/apps.cpp b/src/protocol/masto-api/apps.cpp index 3e4769b..193138b 100644 --- a/src/protocol/masto-api/apps.cpp +++ b/src/protocol/masto-api/apps.cpp @@ -37,11 +37,11 @@ using namespace Protocol; using namespace std::string_literals; HTTP::Response Route::MastoAPI::create_app(std::any& args, - const HTTP::Request& req, - HTTP::RequestArgs_t& arg) + HTTP::Request& req, + const HTTP::RequestArgs_t& arg) { DESTRUCT_WORMHOLE_ARGS(args); - try_load_args_from_json(req, arg); + try_load_args_from_json(req); Logger::instance() << req.data.data(); diff --git a/src/protocol/masto-api/apps.h b/src/protocol/masto-api/apps.h index 5e7bb0c..ef9b0aa 100644 --- a/src/protocol/masto-api/apps.h +++ b/src/protocol/masto-api/apps.h @@ -26,8 +26,8 @@ namespace Route namespace MastoAPI { HTTP::Response create_app(std::any& args, - const HTTP::Request& req, - HTTP::RequestArgs_t& arg); + HTTP::Request& req, + const HTTP::RequestArgs_t& arg); } } diff --git a/src/protocol/webfinger/webfinger.cpp b/src/protocol/webfinger/webfinger.cpp index 8db2155..a1d4c04 100644 --- a/src/protocol/webfinger/webfinger.cpp +++ b/src/protocol/webfinger/webfinger.cpp @@ -72,7 +72,7 @@ HTTP::Response Route::webfinger(std::any& args, const HTTP::Request& req, const try { - resource = std::move(req.get.at("resource").string()); + resource = std::move(req.param.at("resource").string()); } catch (const std::out_of_range& err) { return HTTP::Error::make_json_error_response("Missing resource parameter", HTTP::Code::BAD_REQUEST);