base_op.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #pragma once
  2. #include <inttypes.h>
  3. #include <stdint.h>
  4. #include <map>
  5. #include <string>
  6. #include "cos_config.h"
  7. #include "op/cos_result.h"
  8. #include "trsf/transfer_handler.h"
  9. namespace qcloud_cos {
  10. class BaseReq;
  11. class BaseResp;
  12. class BaseOp {
  13. public:
  14. /// \brief BaseOp构造函数
  15. ///
  16. /// \param cos_conf Cos配置
  17. explicit BaseOp(const SharedConfig& cos_conf) : m_config(cos_conf) {}
  18. BaseOp() {}
  19. /// \brief BaseOp析构函数
  20. ~BaseOp() {}
  21. /// \brief 获取Cos配置
  22. CosConfig GetCosConfig() const;
  23. /// \brief 获取AppID
  24. uint64_t GetAppId() const;
  25. /// \brief 获取Region
  26. std::string GetRegion() const;
  27. /// \brief 获取AccessKey
  28. std::string GetAccessKey() const;
  29. /// \brief 获取SecretKey
  30. std::string GetSecretKey() const;
  31. /// \brief 获取Token
  32. std::string GetTmpToken() const;
  33. std::string GetDestDomain() const;
  34. bool IsDomainSameToHost() const;
  35. /// \brief 封装了cos Service/Bucket/Object 相关接口的通用操作,
  36. /// 包括签名计算、请求发送、返回内容解析等
  37. ///
  38. /// \param host 目标主机, 以http://开头
  39. /// \param path http path
  40. /// \param req http请求
  41. /// \param req_body http request的body
  42. /// \param resp http返回
  43. /// \param is_ci_req 是否为万象域名请求
  44. ///
  45. /// \return http调用情况(状态码等)
  46. CosResult NormalAction(const std::string& host, const std::string& path,
  47. const BaseReq& req, const std::string& req_body,
  48. bool check_body, BaseResp* resp, bool is_ci_req = false);
  49. /// \brief 封装了cos Service/Bucket/Object相关接口的通用操作,
  50. /// 包括签名计算、请求发送、返回内容解析等
  51. ///
  52. /// \param host 目标主机, 以http://开头
  53. /// \param path http path
  54. /// \param req http请求
  55. /// \param additional_headers http请求需要所需的额外header
  56. /// \param additional_params http请求需要所需的额外params
  57. /// \param req_body http request的body
  58. /// \param resp http返回
  59. /// \param is_ci_req 是否为万象域名请求
  60. ///
  61. /// \return http调用情况(状态码等)
  62. CosResult NormalAction(
  63. const std::string& host, const std::string& path, const BaseReq& req,
  64. const std::map<std::string, std::string>& additional_headers,
  65. const std::map<std::string, std::string>& additional_params,
  66. const std::string& req_body, bool check_body, BaseResp* resp,
  67. bool is_ci_req = false);
  68. /// \brief 下载文件并输出到流中
  69. ///
  70. /// \param host 目标主机, 以http://开头
  71. /// \param path http path
  72. /// \param req http请求
  73. /// \param resp http返回
  74. /// \param os 输出流
  75. ///
  76. /// \return http调用情况(状态码等)
  77. CosResult DownloadAction(const std::string& host, const std::string& path,
  78. const BaseReq& req, BaseResp* resp, std::ostream& os,
  79. const SharedTransferHandler& handler = nullptr);
  80. /// \brief 支持从stream中读入数据并上传
  81. ///
  82. /// \param host 目标主机, 以http://开头
  83. /// \param path http path
  84. /// \param req http请求
  85. /// \param additional_headers http请求需要所需的额外header
  86. /// \param additional_params http请求需要所需的额外params
  87. /// \param is http request的body
  88. /// \param resp http返回
  89. ///
  90. /// \return http调用情况(状态码等)
  91. CosResult UploadAction(
  92. const std::string& host, const std::string& path, const BaseReq& req,
  93. const std::map<std::string, std::string>& additional_headers,
  94. const std::map<std::string, std::string>& additional_params,
  95. std::istream& is, BaseResp* resp, const SharedTransferHandler& handler = nullptr);
  96. std::string GetRealUrl(const std::string& host, const std::string& path,
  97. bool is_https);
  98. protected:
  99. bool CheckConfigValidation() const;
  100. SharedConfig m_config;
  101. };
  102. } // namespace qcloud_cos