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

Method write_request

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

Source from the content-addressed store, hash-verified

6338} // namespace httplib
6339
6340inline bool ClientImpl::write_request(Stream &strm, Request &req,
6341 bool close_connection, Error &error) {
6342 // Prepare additional headers
6343 if (close_connection) {
6344 if (!req.has_header("Connection")) {
6345 req.headers.emplace("Connection", "close");
6346 }
6347 }
6348
6349 if (!req.has_header("Host")) {
6350 if (is_ssl()) {
6351 if (port_ == 443) {
6352 req.headers.emplace("Host", host_);
6353 } else {
6354 req.headers.emplace("Host", host_and_port_);
6355 }
6356 } else {
6357 if (port_ == 80) {
6358 req.headers.emplace("Host", host_);
6359 } else {
6360 req.headers.emplace("Host", host_and_port_);
6361 }
6362 }
6363 }
6364
6365 if (!req.has_header("Accept")) { req.headers.emplace("Accept", "*/*"); }
6366
6367#ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT
6368 if (!req.has_header("User-Agent")) {
6369 auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION;
6370 req.headers.emplace("User-Agent", agent);
6371 }
6372#endif
6373
6374 if (req.body.empty()) {
6375 if (req.content_provider_) {
6376 if (!req.is_chunked_content_provider_) {
6377 if (!req.has_header("Content-Length")) {
6378 auto length = std::to_string(req.content_length_);
6379 req.headers.emplace("Content-Length", length);
6380 }
6381 }
6382 } else {
6383 if (req.method == "POST" || req.method == "PUT" ||
6384 req.method == "PATCH") {
6385 req.headers.emplace("Content-Length", "0");
6386 }
6387 }
6388 } else {
6389 if (!req.has_header("Content-Type")) {
6390 req.headers.emplace("Content-Type", "text/plain");
6391 }
6392
6393 if (!req.has_header("Content-Length")) {
6394 auto length = std::to_string(req.body.size());
6395 req.headers.emplace("Content-Length", length);
6396 }
6397 }

Callers

nothing calls this directly

Calls 13

encode_urlFunction · 0.85
write_headersFunction · 0.85
write_dataFunction · 0.85
has_headerMethod · 0.80
write_formatMethod · 0.80
to_stringFunction · 0.70
stringClass · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected