MCPcopy Create free account
hub / github.com/acl-dev/acl / upload

Method upload

lib_acl_cpp/src/http/http_request.cpp:482–545  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

480}
481
482bool http_request::upload(const char *filepath) {
483 if (filepath == NULL || filepath[0] == '\0') {
484 logger_error("filepath is NULL");
485 return false;
486 }
487
488 const long long fsize = fstream::fsize(filepath);
489 if (fsize <= 0) {
490 logger_error("fsize(%lld) is invalid", fsize);
491 return false;
492 }
493
494 header_.set_content_length(fsize);
495 header_.set_method(HTTP_METHOD_POST);
496
497 bool have_retried = false;
498 bool reuse_conn;
499
500 while (true) {
501 if (!try_open(&reuse_conn)) {
502 logger_error("connect server error");
503 return false;
504 }
505
506 if (!send_file(filepath)) {
507 if (have_retried || !reuse_conn) {
508 logger_error("send file error");
509 return false;
510 }
511 close();
512 have_retried = true;
513 continue;
514 }
515
516 if (client_) {
517 client_->reset();
518 if (client_->read_head()) { // �� HTTP ��Ӧͷ
519 break;
520 }
521 }
522
523 if (last_error() == ECANCELED) {
524 return false;
525 }
526
527 if (have_retried || !reuse_conn) {
528 logger_error("read response header error");
529 return false;
530 }
531
532 close(); // �ȹر�֮ǰ��������
533
534 // ���ڳ����ӣ�����ǵ�һ��IOʧ�ܣ������������һ��
535 have_retried = true;
536 }
537
538 // �����ַ���ת����
539 set_charset_conv();

Callers 1

runMethod · 0.45

Calls 14

send_fileFunction · 0.85
last_errorFunction · 0.85
unlinkFunction · 0.85
requestFunction · 0.85
read_headMethod · 0.80
set_content_typeMethod · 0.80
closeFunction · 0.50
uploadFunction · 0.50
resetMethod · 0.45
save_toMethod · 0.45
appendMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected