| 7033 | } |
| 7034 | |
| 7035 | inline bool ClientImpl::write_request(Stream &strm, Request &req, |
| 7036 | bool close_connection, Error &error) { |
| 7037 | // Prepare additional headers |
| 7038 | if (close_connection) { |
| 7039 | if (!req.has_header("Connection")) { |
| 7040 | req.set_header("Connection", "close"); |
| 7041 | } |
| 7042 | } |
| 7043 | |
| 7044 | if (!req.has_header("Host")) { |
| 7045 | if (is_ssl()) { |
| 7046 | if (port_ == 443) { |
| 7047 | req.set_header("Host", host_); |
| 7048 | } else { |
| 7049 | req.set_header("Host", host_and_port_); |
| 7050 | } |
| 7051 | } else { |
| 7052 | if (port_ == 80) { |
| 7053 | req.set_header("Host", host_); |
| 7054 | } else { |
| 7055 | req.set_header("Host", host_and_port_); |
| 7056 | } |
| 7057 | } |
| 7058 | } |
| 7059 | |
| 7060 | if (!req.has_header("Accept")) { req.set_header("Accept", "*/*"); } |
| 7061 | |
| 7062 | #ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT |
| 7063 | if (!req.has_header("User-Agent")) { |
| 7064 | auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION; |
| 7065 | req.set_header("User-Agent", agent); |
| 7066 | } |
| 7067 | #endif |
| 7068 | |
| 7069 | if (req.body.empty()) { |
| 7070 | if (req.content_provider_) { |
| 7071 | if (!req.is_chunked_content_provider_) { |
| 7072 | if (!req.has_header("Content-Length")) { |
| 7073 | auto length = std::to_string(req.content_length_); |
| 7074 | req.set_header("Content-Length", length); |
| 7075 | } |
| 7076 | } |
| 7077 | } else { |
| 7078 | if (req.method == "POST" || req.method == "PUT" || |
| 7079 | req.method == "PATCH") { |
| 7080 | req.set_header("Content-Length", "0"); |
| 7081 | } |
| 7082 | } |
| 7083 | } else { |
| 7084 | if (!req.has_header("Content-Type")) { |
| 7085 | req.set_header("Content-Type", "text/plain"); |
| 7086 | } |
| 7087 | |
| 7088 | if (!req.has_header("Content-Length")) { |
| 7089 | auto length = std::to_string(req.body.size()); |
| 7090 | req.set_header("Content-Length", length); |
| 7091 | } |
| 7092 | } |
nothing calls this directly
no test coverage detected