| 164 | } |
| 165 | |
| 166 | size_t parseContentLength(const std::string& headers) |
| 167 | { |
| 168 | size_t pos = headers.find("Content-Length:"); |
| 169 | if (pos == std::string::npos) { |
| 170 | pos = headers.find("Content-length:"); |
| 171 | } |
| 172 | if (pos == std::string::npos) { |
| 173 | return 0; |
| 174 | } |
| 175 | pos += strlen("Content-Length:"); |
| 176 | while (pos < headers.size() && (headers[pos] == ' ' || headers[pos] == '\t')) { |
| 177 | pos++; |
| 178 | } |
| 179 | size_t end = headers.find("\r\n", pos); |
| 180 | if (end == std::string::npos) { |
| 181 | end = headers.size(); |
| 182 | } |
| 183 | return (size_t)strtoul(headers.substr(pos, end - pos).c_str(), nullptr, 10); |
| 184 | } |
| 185 | |
| 186 | // Streams the body of an upload request to `tmpPath`, tracking progress and |
| 187 | // honouring a receive cancel. `leftover` is the body bytes already read while |
no test coverage detected