MCPcopy Create free account
hub / github.com/chrxh/alien / write_request

Method write_request

external/cpp-httplib/httplib.h:6277–6398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6275 } // namespace httplib
6276
6277 inline bool ClientImpl::write_request(Stream& strm, Request& req,
6278 bool close_connection, Error& error) {
6279 // Prepare additional headers
6280 if (close_connection) {
6281 if (!req.has_header("Connection")) {
6282 req.headers.emplace("Connection", "close");
6283 }
6284 }
6285
6286 if (!req.has_header("Host")) {
6287 if (is_ssl()) {
6288 if (port_ == 443) {
6289 req.headers.emplace("Host", host_);
6290 }
6291 else {
6292 req.headers.emplace("Host", host_and_port_);
6293 }
6294 }
6295 else {
6296 if (port_ == 80) {
6297 req.headers.emplace("Host", host_);
6298 }
6299 else {
6300 req.headers.emplace("Host", host_and_port_);
6301 }
6302 }
6303 }
6304
6305 if (!req.has_header("Accept")) { req.headers.emplace("Accept", "*/*"); }
6306
6307#ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT
6308 if (!req.has_header("User-Agent")) {
6309 auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION;
6310 req.headers.emplace("User-Agent", agent);
6311 }
6312#endif
6313
6314 if (req.body.empty()) {
6315 if (req.content_provider_) {
6316 if (!req.is_chunked_content_provider_) {
6317 if (!req.has_header("Content-Length")) {
6318 auto length = std::to_string(req.content_length_);
6319 req.headers.emplace("Content-Length", length);
6320 }
6321 }
6322 }
6323 else {
6324 if (req.method == "POST" || req.method == "PUT" ||
6325 req.method == "PATCH") {
6326 req.headers.emplace("Content-Length", "0");
6327 }
6328 }
6329 }
6330 else {
6331 if (!req.has_header("Content-Type")) {
6332 req.headers.emplace("Content-Type", "text/plain");
6333 }
6334

Callers

nothing calls this directly

Calls 9

to_stringFunction · 0.85
encode_urlFunction · 0.85
write_headersFunction · 0.85
write_dataFunction · 0.85
has_headerMethod · 0.80
sizeMethod · 0.80
write_formatMethod · 0.80

Tested by

no test coverage detected