@brief write response
| 300 | |
| 301 | ///@brief write response |
| 302 | void HttpSession::write_response() { |
| 303 | auto self = shared_from_this(); |
| 304 | |
| 305 | // header_print("⬆️ ", "Outgoing Response: "); |
| 306 | // header_print("LOG", "Time stamp: " << get_current_time_string()); // hh:mm:ss mm:dd:yyyy |
| 307 | |
| 308 | // Check if this is one of the endpoints where we should skip printing the response body |
| 309 | std::string target = std::string(req_.target()); |
| 310 | bool skip_body_print = (target == "/api/ps" || target == "/api/tags" || target == "/api/version" || target == "/v1/models" || target == "/api/show"); |
| 311 | |
| 312 | //if (!skip_body_print) { |
| 313 | // try{ |
| 314 | // nlohmann::json response_json = json::parse(res_.body()); |
| 315 | // brief_print_message_request(response_json); |
| 316 | // // std::cout << "response_json: " << response_json.dump(4) << std::endl; |
| 317 | // } catch (const std::exception& e) { |
| 318 | // header_print("LOG", "Body: "); |
| 319 | // std::cout << res_.body() << std::endl; |
| 320 | // } |
| 321 | //} |
| 322 | |
| 323 | std::cout << "================================================" << std::endl; |
| 324 | |
| 325 | res_.set("Access-Control-Allow-Origin", "*"); |
| 326 | res_.set("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); |
| 327 | res_.set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With"); |
| 328 | |
| 329 | |
| 330 | http::async_write(socket_, res_, |
| 331 | [self](beast::error_code ec, std::size_t) { |
| 332 | self->socket_.shutdown(tcp::socket::shutdown_both, ec); |
| 333 | // Decrement connection counter for non-keep-alive connections |
| 334 | self->server_.active_connections_.fetch_sub(1); |
| 335 | try { |
| 336 | header_print("🔒 ", "TCP connection closed - Remote: " + self->socket_.remote_endpoint().address().to_string() + ":" + std::to_string(self->socket_.remote_endpoint().port())); |
| 337 | } |
| 338 | catch (...) { |
| 339 | header_print("🔒 ", "TCP connection closed - Remote endpoint unavailable"); |
| 340 | } |
| 341 | |
| 342 | }); |
| 343 | } |
| 344 | |
| 345 | ///@brief write response from callback (for queued requests) |
| 346 | void HttpSession::write_response_from_callback() { |
no test coverage detected