Older/Server/ServiceLogic.h
2024-01-24 23:19:53 +08:00

47 lines
1.8 KiB
C++

#ifndef SERVICELOGIC_H
#define SERVICELOGIC_H
#include "Application.h"
#include "ResponseUtility.h"
#include "StringUtility.h"
#include <boost/beast/http/message.hpp>
#include <boost/beast/http/string_body.hpp>
#include <boost/beast/http/vector_body.hpp>
#include <boost/beast/version.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <fstream>
using StringRequest = boost::beast::http::request<boost::beast::http::string_body>;
namespace ServiceLogic {
template <class Send>
static void onWechat(const Application::Pointer &app, StringRequest &&request, Send &&send);
// Returns a server error response
boost::beast::http::response<boost::beast::http::string_body>
serverError(const boost::beast::http::request<boost::beast::http::string_body> &request, std::string_view errorMessage);
boost::beast::http::response<boost::beast::http::string_body>
badRequest(const boost::beast::http::request<boost::beast::http::string_body> &request, std::string_view why);
template <class ResponseBody, class RequestBody>
boost::beast::http::response<ResponseBody> make_200(const boost::beast::http::request<RequestBody> &request,
typename ResponseBody::value_type body,
boost::beast::string_view content) {
boost::beast::http::response<ResponseBody> response{boost::beast::http::status::ok, request.version()};
response.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING);
response.set(boost::beast::http::field::content_type, content);
response.body() = body;
response.prepare_payload();
response.keep_alive(request.keep_alive());
return response;
}
}; // namespace ServiceLogic
#include "ServiceLogic.inl"
#endif // SERVICELOGIC_H