@brief write streaming response @param data the data @param is_final the is final
| 393 | ///@param data the data |
| 394 | ///@param is_final the is final |
| 395 | void HttpSession::write_streaming_response(const json& data, bool is_final) { |
| 396 | if (!is_streaming_) { |
| 397 | // Initialize streaming response headers |
| 398 | is_streaming_ = true; |
| 399 | res_.result(http::status::ok); |
| 400 | res_.set(http::field::content_type, "application/x-ndjson"); |
| 401 | res_.set(http::field::cache_control, "no-cache"); |
| 402 | res_.set(http::field::connection, "keep-alive"); |
| 403 | res_.set(http::field::transfer_encoding, "chunked"); |
| 404 | |
| 405 | // Send headers immediately using raw socket write |
| 406 | std::string headers = "HTTP/1.1 200 OK\r\n"; |
| 407 | headers += "Content-Type: text/event-stream\r\n"; |
| 408 | headers += "Cache-Control: no-cache\r\n"; |
| 409 | headers += "Connection: keep-alive\r\n"; |
| 410 | headers += "Transfer-Encoding: chunked\r\n"; |
| 411 | headers += "Access-Control-Allow-Origin: *\r\n"; |
| 412 | headers += "Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n"; |
| 413 | headers += "Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With\r\n"; |
| 414 | headers += "\r\n"; |
| 415 | |
| 416 | // Send headers synchronously |
| 417 | boost::system::error_code ec; |
| 418 | net::write(socket_, net::buffer(headers), ec); |
| 419 | if (ec) return; |
| 420 | } |
| 421 | |
| 422 | // Send this chunk immediately |
| 423 | send_chunk_data(data, is_final); |
| 424 | } |
| 425 | |
| 426 | ///@brief send chunk data |
| 427 | ///@param data the data |
no test coverage detected