287144 {
287145
287146 buf_append(buf, n);
287147
287148 while (buf_size() > 0) {
287149 switch (state_) {
287150 case 0: {
287151 auto pos = buf_find(dash_boundary_crlf_);
287152 if (pos == buf_size()) { return true; }
287153 buf_erase(pos + dash_boundary_crlf_.size());
287154 state_ = 1;
287155 break;
287156 }
287157 case 1: {
287158 clear_file_info();
287159 state_ = 2;
287160 break;
287161 }
287162 case 2: {
287163 auto pos = buf_find(crlf_);
287164 if (pos > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; }
287165 while (pos < buf_size()) {
287166
287167 if (pos == 0) {
287168 if (!header_callback(file_)) {
287169 is_valid_ = false;
287170 return false;
287171 }
287172 buf_erase(crlf_.size());
287173 state_ = 3;
287174 break;
287175 }
287176
287177 const auto header = buf_head(pos);
287178
287179 if (!parse_header(header.data(), header.data() + header.size(),
287180 [&](const std::string &, const std::string &) {})) {
287181 is_valid_ = false;
287182 return false;
287183 }
287184
287185
287186 if (!parse_header(
287187 header.data(), header.data() + header.size(),
287188 [&](const std::string &key, const std::string &val) {
287189 file_.headers.emplace(key, val);
287190 })) {
287191 is_valid_ = false;
287192 return false;
287193 }
287194
287195 constexpr const char header_content_type[] = "Content-Type:";
287196
287197 if (start_with_case_ignore(header, header_content_type)) {
287198 file_.content_type =
287199 trim_copy(header.substr(str_len(header_content_type)));
287200 } else {
287201 REGEX_SCOPE const Regex re_content_disposition(
287202 R"~(^Content-Disposition:\s*form-data;\s*(.*)$)~",
287203 duckdb_re2::RegexOptions::CASE_INSENSITIVE);
287204
287206 if (RegexMatch(header, m, re_content_disposition)) {
287208 parse_disposition_params(m[1], params);
287209
287210 auto it =
params.find(
"name");
287211 if (it !=
params.end()) {
287212 file_.name = it->second;
287213 } else {
287214 is_valid_ = false;
287215 return false;
287216 }
287217
287218 it =
params.find(
"filename");
287219 if (it !=
params.end()) { file_.filename = it->second; }
287220
287221 it =
params.find(
"filename*");
287222 if (it !=
params.end()) {
287223
287224 REGEX_SCOPE const Regex re_rfc5987_encoding(
287225 R"~(^UTF-8''(.+?)$)~", duckdb_re2::RegexOptions::CASE_INSENSITIVE);
287226
287228 if (RegexMatch(it->second, m2, re_rfc5987_encoding)) {
287229 file_.filename = decode_path_component(m2[1]);
287230 } else {
287231 is_valid_ = false;
287232 return false;
287233 }
287234 }
287235 }
287236 }
287237 buf_erase(pos + crlf_.size());
287238 pos = buf_find(crlf_);
287239 }
287240 if (state_ != 3) { return true; }
287241 break;
287242 }
287243 case 3: {
287244 if (crlf_dash_boundary_.size() > buf_size()) { return true; }
287245 auto pos = buf_find(crlf_dash_boundary_);
287246 if (pos < buf_size()) {
287247 if (!content_callback(buf_data(), pos)) {
287248 is_valid_ = false;
287249 return false;
287250 }
287251 buf_erase(pos + crlf_dash_boundary_.size());
287252 state_ = 4;
287253 } else {
287254 auto len = buf_size() - crlf_dash_boundary_.size();
287255 if (len > 0) {
287256 if (!content_callback(buf_data(), len)) {
287257 is_valid_ = false;
287258 return false;
287259 }
287260 buf_erase(len);
287261 }
287262 return true;
287263 }
287264 break;
287265 }
287266 case 4: {
287267 if (crlf_.size() > buf_size()) { return true; }
287268 if (buf_start_with(crlf_)) {
287269 buf_erase(crlf_.size());
287270 state_ = 1;
287271 } else {
287272 if (dash_.size() > buf_size()) { return true; }
287273 if (buf_start_with(dash_)) {
287274 buf_erase(dash_.size());
287275 is_valid_ = true;
287276 buf_erase(buf_size());
287277 } else {
287278 return true;
287279 }
287280 }
287281 break;
287282 }
287283 }
287284 }
287285
287286 return true;
287287 }
Match(int x, int y, float similarity, const String &class_id, int template_id)
PyParams params(const std::string &tag, const std::string &model, const std::string &weights, const std::string &device)