| 545 | } |
| 546 | |
| 547 | bool http_request::send_file(const char *filepath) const { |
| 548 | // ���뱣֤�������Ѿ��� |
| 549 | if (client_ == NULL) { |
| 550 | logger_error("connection not opened yet!"); |
| 551 | return false; |
| 552 | } |
| 553 | |
| 554 | client_->reset(); // ����״̬ |
| 555 | |
| 556 | // д HTTP ����ͷ |
| 557 | if (!client_->write_head(header_)) { |
| 558 | return false; |
| 559 | } |
| 560 | |
| 561 | ifstream in; |
| 562 | if (!in.open_read(filepath)) { |
| 563 | logger_error("open %s error: %s", filepath, last_serror()); |
| 564 | return false; |
| 565 | } |
| 566 | |
| 567 | char buf[8192]; |
| 568 | while (!in.eof()) { |
| 569 | const int ret = in.read(buf, sizeof(buf), false); |
| 570 | if (ret <= 0) { |
| 571 | break; |
| 572 | } |
| 573 | if (!client_->write_body(buf, ret)) { |
| 574 | return false; |
| 575 | } |
| 576 | } |
| 577 | return true; |
| 578 | } |
| 579 | |
| 580 | bool http_request::upload(http_mime &mime, const char *filepath, bool savefile) { |
| 581 | if (filepath == NULL || filepath[0] == '\0') { |
nothing calls this directly
no test coverage detected