| 7654 | } |
| 7655 | |
| 7656 | inline bool ClientImpl::write_request(Stream &strm, Request &req, |
| 7657 | bool close_connection, Error &error) { |
| 7658 | // Prepare additional headers |
| 7659 | if (close_connection) { |
| 7660 | if (!req.has_header("Connection")) { |
| 7661 | req.set_header("Connection", "close"); |
| 7662 | } |
| 7663 | } |
| 7664 | |
| 7665 | if (!req.has_header("Host")) { |
| 7666 | if (is_ssl()) { |
| 7667 | if (port_ == 443) { |
| 7668 | req.set_header("Host", host_); |
| 7669 | } else { |
| 7670 | req.set_header("Host", host_and_port_); |
| 7671 | } |
| 7672 | } else { |
| 7673 | if (port_ == 80) { |
| 7674 | req.set_header("Host", host_); |
| 7675 | } else { |
| 7676 | req.set_header("Host", host_and_port_); |
| 7677 | } |
| 7678 | } |
| 7679 | } |
| 7680 | |
| 7681 | if (!req.has_header("Accept")) { req.set_header("Accept", "*/*"); } |
| 7682 | |
| 7683 | #ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT |
| 7684 | if (!req.has_header("User-Agent")) { |
| 7685 | auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION; |
| 7686 | req.set_header("User-Agent", agent); |
| 7687 | } |
| 7688 | #endif |
| 7689 | |
| 7690 | if (req.body.empty()) { |
| 7691 | if (req.content_provider_) { |
| 7692 | if (!req.is_chunked_content_provider_) { |
| 7693 | if (!req.has_header("Content-Length")) { |
| 7694 | auto length = std::to_string(req.content_length_); |
| 7695 | req.set_header("Content-Length", length); |
| 7696 | } |
| 7697 | } |
| 7698 | } else { |
| 7699 | if (req.method == "POST" || req.method == "PUT" || |
| 7700 | req.method == "PATCH") { |
| 7701 | req.set_header("Content-Length", "0"); |
| 7702 | } |
| 7703 | } |
| 7704 | } else { |
| 7705 | if (!req.has_header("Content-Type")) { |
| 7706 | req.set_header("Content-Type", "text/plain"); |
| 7707 | } |
| 7708 | |
| 7709 | if (!req.has_header("Content-Length")) { |
| 7710 | auto length = std::to_string(req.body.size()); |
| 7711 | req.set_header("Content-Length", length); |
| 7712 | } |
| 7713 | } |
nothing calls this directly
no test coverage detected