Browse Source

cleanup of http file

master
Jørgen Sverre Lien Sellæg 5 years ago
parent
commit
556d31eee4
  1. 4
      include/http.hpp
  2. 41
      src/http.cpp
  3. 2
      src/store.cpp

4
include/http.hpp

@ -12,8 +12,8 @@ public:
static void https_required(std::shared_ptr<HttpsServer::Response> response);
static void bad_json(std::shared_ptr<HttpServer::Response> response);
static void bad_json(std::shared_ptr<HttpsServer::Response> response);
static void bad_object(std::shared_ptr<HttpServer::Response> response);
static void bad_object(std::shared_ptr<HttpsServer::Response> response);
static void bad_request(std::shared_ptr<HttpServer::Response> response);
static void bad_request(std::shared_ptr<HttpsServer::Response> response);
static void not_found(std::shared_ptr<HttpServer::Response> response);
static void not_found(std::shared_ptr<HttpsServer::Response> response);
};

41
src/http.cpp

@ -1,49 +1,26 @@
#include <http.hpp>
#include <json.hpp>
const auto https_required_msg = json::object({
{"message", "100: Your server is configured to use https, but a "
"request on http was received."},
});
// const auto https_required_msg = json::object({
// {"message", "100: Your server is configured to use https, but a "
// "request on http was received."},
// });
const auto bad_json_msg = json::object({
{"message", "101: Your request was not a valid JSON document."},
});
// const auto bad_json_msg = json::object({
// {"message", "101: Your request was not a valid JSON document."},
// });
const auto bad_object_msg = json::object({
{"message", "102: Your request was not a valid store."},
});
void response::https_required(std::shared_ptr<HttpServer::Response> response) {
return response->write(Status::client_error_bad_request,
https_required_msg.dump(),
{header_access_control, header_application_data});
}
void response::https_required(std::shared_ptr<HttpsServer::Response> response) {
return response->write(Status::client_error_bad_request,
https_required_msg.dump(),
{header_access_control, header_application_data});
}
void response::bad_json(std::shared_ptr<HttpServer::Response> response) {
return response->write(Status::client_error_bad_request, bad_json_msg.dump(),
{header_access_control, header_application_data});
}
void response::bad_json(std::shared_ptr<HttpsServer::Response> response) {
return response->write(Status::client_error_bad_request, bad_json_msg.dump(),
{header_access_control, header_application_data});
}
void response::bad_object(std::shared_ptr<HttpServer::Response> response) {
void response::bad_request(std::shared_ptr<HttpServer::Response> response) {
return response->write(Status::client_error_bad_request,
bad_object_msg.dump(),
{header_access_control, header_application_data});
}
void response::bad_object(std::shared_ptr<HttpsServer::Response> response) {
void response::bad_request(std::shared_ptr<HttpsServer::Response> response) {
return response->write(Status::client_error_bad_request,
bad_object_msg.dump(),
{header_access_control, header_application_data});

2
src/store.cpp

@ -81,7 +81,7 @@ int Application::run() {
const auto json_response = dat.process(data);
if (json_response.is_null()) {
return response::bad_object(response);
return response::bad_request(response);
}
response->write(Status::success_created, json_response.dump(),

Loading…
Cancel
Save