| 124 | } |
| 125 | |
| 126 | std::vector<MultipartPart> parse_multipart_body(const std::string & body, const std::string & boundary) { |
| 127 | std::vector<MultipartPart> parts; |
| 128 | const std::string delimiter = "--" + boundary; |
| 129 | |
| 130 | size_t pos = body.find(delimiter); |
| 131 | if (pos == std::string::npos) { |
| 132 | return parts; |
| 133 | } |
| 134 | pos += delimiter.size(); |
| 135 | |
| 136 | while (true) { |
| 137 | if (body.compare(pos, 2, "--") == 0) { |
| 138 | break; |
| 139 | } |
| 140 | if (body.compare(pos, 2, "\r\n") == 0) { |
| 141 | pos += 2; |
| 142 | } else if (pos < body.size() && body[pos] == '\n') { |
| 143 | pos += 1; |
| 144 | } |
| 145 | |
| 146 | const size_t next_delim = body.find(delimiter, pos); |
| 147 | if (next_delim == std::string::npos) { |
| 148 | break; |
| 149 | } |
| 150 | |
| 151 | const std::string segment = strip_trailing_newline(body.substr(pos, next_delim - pos)); |
| 152 | parts.push_back(parse_part(segment)); |
| 153 | pos = next_delim + delimiter.size(); |
| 154 | } |
| 155 | |
| 156 | return parts; |
| 157 | } |
| 158 | |
| 159 | } // namespace minitts::server |