MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / write_request

Method write_request

examples/server/httplib.h:6614–6730  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6612}
6613
6614inline bool ClientImpl::write_request(Stream &strm, Request &req,
6615 bool close_connection, Error &error) {
6616 // Prepare additional headers
6617 if (close_connection) {
6618 if (!req.has_header("Connection")) {
6619 req.headers.emplace("Connection", "close");
6620 }
6621 }
6622
6623 if (!req.has_header("Host")) {
6624 if (is_ssl()) {
6625 if (port_ == 443) {
6626 req.headers.emplace("Host", host_);
6627 } else {
6628 req.headers.emplace("Host", host_and_port_);
6629 }
6630 } else {
6631 if (port_ == 80) {
6632 req.headers.emplace("Host", host_);
6633 } else {
6634 req.headers.emplace("Host", host_and_port_);
6635 }
6636 }
6637 }
6638
6639 if (!req.has_header("Accept")) { req.headers.emplace("Accept", "*/*"); }
6640
6641#ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT
6642 if (!req.has_header("User-Agent")) {
6643 auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION;
6644 req.headers.emplace("User-Agent", agent);
6645 }
6646#endif
6647
6648 if (req.body.empty()) {
6649 if (req.content_provider_) {
6650 if (!req.is_chunked_content_provider_) {
6651 if (!req.has_header("Content-Length")) {
6652 auto length = std::to_string(req.content_length_);
6653 req.headers.emplace("Content-Length", length);
6654 }
6655 }
6656 } else {
6657 if (req.method == "POST" || req.method == "PUT" ||
6658 req.method == "PATCH") {
6659 req.headers.emplace("Content-Length", "0");
6660 }
6661 }
6662 } else {
6663 if (!req.has_header("Content-Type")) {
6664 req.headers.emplace("Content-Type", "text/plain");
6665 }
6666
6667 if (!req.has_header("Content-Length")) {
6668 auto length = std::to_string(req.body.size());
6669 req.headers.emplace("Content-Length", length);
6670 }
6671 }

Callers

nothing calls this directly

Calls 15

encode_urlFunction · 0.85
write_headersFunction · 0.85
write_dataFunction · 0.85
has_headerMethod · 0.80
write_formatMethod · 0.80
get_bufferMethod · 0.80
stringFunction · 0.70
to_stringFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected