| 88 | } |
| 89 | |
| 90 | static size_t parseContentLength(const std::string& headers) |
| 91 | { |
| 92 | size_t pos = headers.find("Content-Length:"); |
| 93 | if (pos == std::string::npos) { |
| 94 | pos = headers.find("Content-length:"); |
| 95 | } |
| 96 | if (pos == std::string::npos) { |
| 97 | return 0; |
| 98 | } |
| 99 | pos += strlen("Content-Length:"); |
| 100 | while (pos < headers.size() && (headers[pos] == ' ' || headers[pos] == '\t')) { |
| 101 | pos++; |
| 102 | } |
| 103 | size_t end = headers.find("\r\n", pos); |
| 104 | if (end == std::string::npos) { |
| 105 | end = headers.size(); |
| 106 | } |
| 107 | return (size_t)strtoul(headers.substr(pos, end - pos).c_str(), nullptr, 10); |
| 108 | } |
| 109 | |
| 110 | // Per-recv idle timeout. The server is single-threaded, so without a bound a |
| 111 | // stalled (or malicious) client would hang the whole receiver indefinitely. |
no test coverage detected