file_download_task.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (c) 2017, Tencent Inc.
  2. // All rights reserved.
  3. //
  4. // Author: sevenyou <sevenyou@tencent.com>
  5. // Created: 07/25/17
  6. // Description:
  7. #pragma once
  8. #include <stdint.h>
  9. #include <map>
  10. #include <string>
  11. #include "Poco/Foundation.h"
  12. #include "Poco/Runnable.h"
  13. #include "cos_config.h"
  14. #include "trsf/transfer_handler.h"
  15. namespace qcloud_cos {
  16. class FileDownTask : public Poco::Runnable {
  17. public:
  18. FileDownTask(const std::string& full_url,
  19. const std::map<std::string, std::string>& headers,
  20. const std::map<std::string, std::string>& params,
  21. uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms,
  22. const SharedTransferHandler& handler = nullptr,
  23. uint64_t offset = 0, unsigned char* pbuf = NULL,
  24. const size_t data_len = 0,
  25. bool verify_cert = true,
  26. const std::string& ca_lication = "");
  27. ~FileDownTask() {}
  28. void run();
  29. void DownTask();
  30. void SetDownParams(unsigned char* pdatabuf, size_t datalen, uint64_t offset);
  31. void SetVerifyCert(bool verify_cert);
  32. void SetCaLocation(const std::string& ca_location);
  33. std::string GetTaskResp();
  34. size_t GetDownLoadLen();
  35. bool IsTaskSuccess();
  36. int GetHttpStatus();
  37. std::map<std::string, std::string> GetRespHeaders();
  38. std::string GetErrMsg() const { return m_err_msg; }
  39. private:
  40. std::string m_full_url;
  41. std::map<std::string, std::string> m_headers;
  42. std::map<std::string, std::string> m_params;
  43. uint64_t m_conn_timeout_in_ms;
  44. uint64_t m_recv_timeout_in_ms;
  45. SharedTransferHandler m_handler;
  46. uint64_t m_offset;
  47. unsigned char* m_data_buf_ptr;
  48. size_t m_data_len;
  49. std::string m_resp;
  50. bool m_is_task_success;
  51. size_t m_real_down_len;
  52. int m_http_status;
  53. std::map<std::string, std::string> m_resp_headers;
  54. std::string m_err_msg;
  55. bool m_verify_cert;
  56. std::string m_ca_location;
  57. SharedConfig m_config;
  58. };
  59. } // namespace qcloud_cos