Skip to content

Commit be00638

Browse files
committed
fix: 无法获取PIN设备列表
1 parent 410678f commit be00638

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

src/confighttp.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <boost/asio/ssl/context.hpp>
2323

2424
#include <boost/filesystem.hpp>
25-
25+
#include <nlohmann/json.hpp>
2626
#include <Simple-Web-Server/crypto.hpp>
2727
#include <Simple-Web-Server/server_https.hpp>
2828
#include <boost/asio/ssl/context_base.hpp>
@@ -80,6 +80,19 @@ namespace confighttp {
8080
BOOST_LOG(debug) << " [--] "sv;
8181
}
8282

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+
8396
void
8497
send_unauthorized(resp_https_t response, req_https_t request) {
8598
auto address = net::addr_to_normalized_string(request->remote_endpoint().address());
@@ -941,21 +954,11 @@ namespace confighttp {
941954
if (!authenticate(response, request)) return;
942955

943956
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);
959962
}
960963

961964
void

0 commit comments

Comments
 (0)