| 6171 | } // namespace httplib |
| 6172 | |
| 6173 | inline bool ClientImpl::write_request(Stream &strm, Request &req, |
| 6174 | bool close_connection, Error &error) { |
| 6175 | // Prepare additional headers |
| 6176 | if (close_connection) { |
| 6177 | if (!req.has_header("Connection")) { |
| 6178 | req.headers.emplace("Connection", "close"); |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | if (!req.has_header("Host")) { |
| 6183 | if (is_ssl()) { |
| 6184 | if (port_ == 443) { |
| 6185 | req.headers.emplace("Host", host_); |
| 6186 | } else { |
| 6187 | req.headers.emplace("Host", host_and_port_); |
| 6188 | } |
| 6189 | } else { |
| 6190 | if (port_ == 80) { |
| 6191 | req.headers.emplace("Host", host_); |
| 6192 | } else { |
| 6193 | req.headers.emplace("Host", host_and_port_); |
| 6194 | } |
| 6195 | } |
| 6196 | } |
| 6197 | |
| 6198 | if (!req.has_header("Accept")) { req.headers.emplace("Accept", "*/*"); } |
| 6199 | |
| 6200 | #ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT |
| 6201 | if (!req.has_header("User-Agent")) { |
| 6202 | auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION; |
| 6203 | req.headers.emplace("User-Agent", agent); |
| 6204 | } |
| 6205 | #endif |
| 6206 | |
| 6207 | if (req.body.empty()) { |
| 6208 | if (req.content_provider_) { |
| 6209 | if (!req.is_chunked_content_provider_) { |
| 6210 | if (!req.has_header("Content-Length")) { |
| 6211 | auto length = std::to_string(req.content_length_); |
| 6212 | req.headers.emplace("Content-Length", length); |
| 6213 | } |
| 6214 | } |
| 6215 | } else { |
| 6216 | if (req.method == "POST" || req.method == "PUT" || |
| 6217 | req.method == "PATCH") { |
| 6218 | req.headers.emplace("Content-Length", "0"); |
| 6219 | } |
| 6220 | } |
| 6221 | } else { |
| 6222 | if (!req.has_header("Content-Type")) { |
| 6223 | req.headers.emplace("Content-Type", "text/plain"); |
| 6224 | } |
| 6225 | |
| 6226 | if (!req.has_header("Content-Length")) { |
| 6227 | auto length = std::to_string(req.body.size()); |
| 6228 | req.headers.emplace("Content-Length", length); |
| 6229 | } |
| 6230 | } |
nothing calls this directly
no test coverage detected