| 63 | } |
| 64 | |
| 65 | MultipartPart parse_part(const std::string & segment) { |
| 66 | MultipartPart part; |
| 67 | size_t header_end = segment.find("\r\n\r\n"); |
| 68 | size_t separator_len = 4; |
| 69 | if (header_end == std::string::npos) { |
| 70 | header_end = segment.find("\n\n"); |
| 71 | separator_len = 2; |
| 72 | } |
| 73 | if (header_end == std::string::npos) { |
| 74 | return part; |
| 75 | } |
| 76 | |
| 77 | part.data = segment.substr(header_end + separator_len); |
| 78 | |
| 79 | std::istringstream header_stream(segment.substr(0, header_end)); |
| 80 | std::string line; |
| 81 | while (std::getline(header_stream, line)) { |
| 82 | if (!line.empty() && line.back() == '\r') { |
| 83 | line.pop_back(); |
| 84 | } |
| 85 | const auto colon = line.find(':'); |
| 86 | if (colon == std::string::npos) { |
| 87 | continue; |
| 88 | } |
| 89 | const std::string key = lower_ascii(trim(line.substr(0, colon))); |
| 90 | const std::string value = trim(line.substr(colon + 1)); |
| 91 | if (key == "content-disposition") { |
| 92 | part.name = extract_header_param(value, "name"); |
| 93 | part.filename = extract_header_param(value, "filename"); |
| 94 | } |
| 95 | } |
| 96 | return part; |
| 97 | } |
| 98 | |
| 99 | } // namespace |
| 100 |
no test coverage detected