mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 21:55:03 +02:00
Add HttpUtility::SendJsonBody() overload for Boost/Beast
This commit is contained in:
parent
2d7714802d
commit
fc22cbaf09
@ -5,6 +5,7 @@
|
|||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <boost/beast/http.hpp>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
@ -55,6 +56,15 @@ void HttpUtility::SendJsonBody(HttpResponse& response, const Dictionary::Ptr& pa
|
|||||||
response.WriteBody(body.CStr(), body.GetLength());
|
response.WriteBody(body.CStr(), body.GetLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HttpUtility::SendJsonBody(boost::beast::http::response<boost::beast::http::string_body>& response, const Dictionary::Ptr& params, const Value& val)
|
||||||
|
{
|
||||||
|
namespace http = boost::beast::http;
|
||||||
|
|
||||||
|
response.set(http::field::content_type, "application/json");
|
||||||
|
response.body() = JsonEncode(val, params && GetLastParameter(params, "pretty"));
|
||||||
|
response.set(http::field::content_length, response.body().size());
|
||||||
|
}
|
||||||
|
|
||||||
Value HttpUtility::GetLastParameter(const Dictionary::Ptr& params, const String& key)
|
Value HttpUtility::GetLastParameter(const Dictionary::Ptr& params, const String& key)
|
||||||
{
|
{
|
||||||
Value varr = params->Get(key);
|
Value varr = params->Get(key);
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "remote/httprequest.hpp"
|
#include "remote/httprequest.hpp"
|
||||||
#include "remote/httpresponse.hpp"
|
#include "remote/httpresponse.hpp"
|
||||||
#include "base/dictionary.hpp"
|
#include "base/dictionary.hpp"
|
||||||
|
#include <boost/beast/http.hpp>
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
@ -21,6 +22,7 @@ class HttpUtility
|
|||||||
public:
|
public:
|
||||||
static Dictionary::Ptr FetchRequestParameters(HttpRequest& request);
|
static Dictionary::Ptr FetchRequestParameters(HttpRequest& request);
|
||||||
static void SendJsonBody(HttpResponse& response, const Dictionary::Ptr& params, const Value& val);
|
static void SendJsonBody(HttpResponse& response, const Dictionary::Ptr& params, const Value& val);
|
||||||
|
static void SendJsonBody(boost::beast::http::response<boost::beast::http::string_body>& response, const Dictionary::Ptr& params, const Value& val);
|
||||||
static Value GetLastParameter(const Dictionary::Ptr& params, const String& key);
|
static Value GetLastParameter(const Dictionary::Ptr& params, const String& key);
|
||||||
static void SendJsonError(HttpResponse& response, const Dictionary::Ptr& params, const int code,
|
static void SendJsonError(HttpResponse& response, const Dictionary::Ptr& params, const int code,
|
||||||
const String& verbose = String(), const String& diagnosticInformation = String());
|
const String& verbose = String(), const String& diagnosticInformation = String());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user