MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/xstudio / write_response_core

Method write_response_core

extern/include/cpp-httplib/httplib.h:5179–5256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5177}
5178
5179inline bool Server::write_response_core(Stream &strm, bool close_connection,
5180 const Request &req, Response &res,
5181 bool need_apply_ranges) {
5182 assert(res.status != -1);
5183
5184 if (400 <= res.status && error_handler_ &&
5185 error_handler_(req, res) == HandlerResponse::Handled) {
5186 need_apply_ranges = true;
5187 }
5188
5189 std::string content_type;
5190 std::string boundary;
5191 if (need_apply_ranges) { apply_ranges(req, res, content_type, boundary); }
5192
5193 // Prepare additional headers
5194 if (close_connection || req.get_header_value("Connection") == "close") {
5195 res.set_header("Connection", "close");
5196 } else {
5197 std::stringstream ss;
5198 ss << "timeout=" << keep_alive_timeout_sec_
5199 << ", max=" << keep_alive_max_count_;
5200 res.set_header("Keep-Alive", ss.str());
5201 }
5202
5203 if (!res.has_header("Content-Type") &&
5204 (!res.body.empty() || res.content_length_ > 0 || res.content_provider_)) {
5205 res.set_header("Content-Type", "text/plain");
5206 }
5207
5208 if (!res.has_header("Content-Length") && res.body.empty() &&
5209 !res.content_length_ && !res.content_provider_) {
5210 res.set_header("Content-Length", "0");
5211 }
5212
5213 if (!res.has_header("Accept-Ranges") && req.method == "HEAD") {
5214 res.set_header("Accept-Ranges", "bytes");
5215 }
5216
5217 if (post_routing_handler_) { post_routing_handler_(req, res); }
5218
5219 // Response line and headers
5220 {
5221 detail::BufferStream bstrm;
5222
5223 if (!bstrm.write_format("HTTP/1.1 %d %s\r\n", res.status,
5224 detail::status_message(res.status))) {
5225 return false;
5226 }
5227
5228 if (!detail::write_headers(bstrm, res.headers)) { return false; }
5229
5230 // Flush buffer
5231 auto &data = bstrm.get_buffer();
5232 detail::write_data(strm, data.data(), data.size());
5233 }
5234
5235 // Body
5236 auto ret = true;

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected