fix bug: bserv: router: json param: content-type: compare media-type & ignore other params
This commit is contained in:
parent
e7d7b09db7
commit
1ae2bfd5aa
|
@ -209,7 +209,23 @@ namespace bserv {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!resources.request.body().empty()) {
|
if (!resources.request.body().empty()) {
|
||||||
if (resources.request[http::field::content_type] == "application/json") {
|
auto& content_type = resources.request[http::field::content_type];
|
||||||
|
/*
|
||||||
|
for reference:
|
||||||
|
Content-Type: text/html; charset=UTF-8
|
||||||
|
Content-Type: multipart/form-data; boundary=something
|
||||||
|
*/
|
||||||
|
std::string media_type;
|
||||||
|
for (auto& c : content_type) {
|
||||||
|
if (c == ' ') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (c == ';') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
media_type += c;
|
||||||
|
}
|
||||||
|
if (media_type == "application/json") {
|
||||||
try {
|
try {
|
||||||
body = boost::json::parse(resources.request.body()).as_object();
|
body = boost::json::parse(resources.request.body()).as_object();
|
||||||
}
|
}
|
||||||
|
@ -217,7 +233,7 @@ namespace bserv {
|
||||||
throw bad_request_exception{};
|
throw bad_request_exception{};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (resources.request[http::field::content_type] == "application/x-www-form-urlencoded") {
|
else if (media_type == "application/x-www-form-urlencoded") {
|
||||||
std::string copied_body{ resources.request.body() };
|
std::string copied_body{ resources.request.body() };
|
||||||
auto&& [dict_params, list_params] = utils::parse_params(copied_body);
|
auto&& [dict_params, list_params] = utils::parse_params(copied_body);
|
||||||
add_to_body(dict_params, list_params);
|
add_to_body(dict_params, list_params);
|
||||||
|
|
Loading…
Reference in New Issue