|
22 | 22 | #include <boost/asio/ssl/context.hpp> |
23 | 23 |
|
24 | 24 | #include <boost/filesystem.hpp> |
25 | | - |
| 25 | +#include <nlohmann/json.hpp> |
26 | 26 | #include <Simple-Web-Server/crypto.hpp> |
27 | 27 | #include <Simple-Web-Server/server_https.hpp> |
28 | 28 | #include <boost/asio/ssl/context_base.hpp> |
@@ -80,6 +80,19 @@ namespace confighttp { |
80 | 80 | BOOST_LOG(debug) << " [--] "sv; |
81 | 81 | } |
82 | 82 |
|
| 83 | + /** |
| 84 | + * @brief Send a response. |
| 85 | + * @param response The HTTP response object. |
| 86 | + * @param output_tree The JSON tree to send. |
| 87 | + */ |
| 88 | + void send_response(resp_https_t response, const nlohmann::json &output_tree) { |
| 89 | + SimpleWeb::CaseInsensitiveMultimap headers; |
| 90 | + headers.emplace("Content-Type", "application/json"); |
| 91 | + headers.emplace("X-Frame-Options", "DENY"); |
| 92 | + headers.emplace("Content-Security-Policy", "frame-ancestors 'none';"); |
| 93 | + response->write(output_tree.dump(), headers); |
| 94 | + } |
| 95 | + |
83 | 96 | void |
84 | 97 | send_unauthorized(resp_https_t response, req_https_t request) { |
85 | 98 | auto address = net::addr_to_normalized_string(request->remote_endpoint().address()); |
@@ -941,21 +954,11 @@ namespace confighttp { |
941 | 954 | if (!authenticate(response, request)) return; |
942 | 955 |
|
943 | 956 | print_req(request); |
944 | | - |
945 | | - pt::ptree named_certs = nvhttp::get_all_clients(); |
946 | | - |
947 | | - pt::ptree outputTree; |
948 | | - |
949 | | - outputTree.put("status", false); |
950 | | - |
951 | | - auto g = util::fail_guard([&]() { |
952 | | - std::ostringstream data; |
953 | | - pt::write_json(data, outputTree); |
954 | | - response->write(data.str()); |
955 | | - }); |
956 | | - |
957 | | - outputTree.add_child("named_certs", named_certs); |
958 | | - outputTree.put("status", true); |
| 957 | + const nlohmann::json named_certs = nvhttp::get_all_clients(); |
| 958 | + nlohmann::json output_tree; |
| 959 | + output_tree["named_certs"] = named_certs; |
| 960 | + output_tree["status"] = true; |
| 961 | + send_response(response, output_tree); |
959 | 962 | } |
960 | 963 |
|
961 | 964 | void |
|
0 commit comments