MCPcopy Create free account
hub / github.com/PABannier/bark.cpp / write_response_core

Method write_response_core

examples/server/httplib.h:5842–5919  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5840}
5841
5842inline bool Server::write_response_core(Stream &strm, bool close_connection,
5843 const Request &req, Response &res,
5844 bool need_apply_ranges) {
5845 assert(res.status != -1);
5846
5847 if (400 <= res.status && error_handler_ &&
5848 error_handler_(req, res) == HandlerResponse::Handled) {
5849 need_apply_ranges = true;
5850 }
5851
5852 std::string content_type;
5853 std::string boundary;
5854 if (need_apply_ranges) { apply_ranges(req, res, content_type, boundary); }
5855
5856 // Prepare additional headers
5857 if (close_connection || req.get_header_value("Connection") == "close") {
5858 res.set_header("Connection", "close");
5859 } else {
5860 std::stringstream ss;
5861 ss << "timeout=" << keep_alive_timeout_sec_
5862 << ", max=" << keep_alive_max_count_;
5863 res.set_header("Keep-Alive", ss.str());
5864 }
5865
5866 if (!res.has_header("Content-Type") &&
5867 (!res.body.empty() || res.content_length_ > 0 || res.content_provider_)) {
5868 res.set_header("Content-Type", "text/plain");
5869 }
5870
5871 if (!res.has_header("Content-Length") && res.body.empty() &&
5872 !res.content_length_ && !res.content_provider_) {
5873 res.set_header("Content-Length", "0");
5874 }
5875
5876 if (!res.has_header("Accept-Ranges") && req.method == "HEAD") {
5877 res.set_header("Accept-Ranges", "bytes");
5878 }
5879
5880 if (post_routing_handler_) { post_routing_handler_(req, res); }
5881
5882 // Response line and headers
5883 {
5884 detail::BufferStream bstrm;
5885
5886 if (!bstrm.write_format("HTTP/1.1 %d %s\r\n", res.status,
5887 status_message(res.status))) {
5888 return false;
5889 }
5890
5891 if (!header_writer_(bstrm, res.headers)) { return false; }
5892
5893 // Flush buffer
5894 auto &data = bstrm.get_buffer();
5895 detail::write_data(strm, data.data(), data.size());
5896 }
5897
5898 // Body
5899 auto ret = true;

Callers

nothing calls this directly

Calls 9

status_messageFunction · 0.85
write_dataFunction · 0.85
get_header_valueMethod · 0.80
set_headerMethod · 0.80
has_headerMethod · 0.80
emptyMethod · 0.80
write_formatMethod · 0.80
dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected