http_sender.h 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (c) 2017, Tencent Inc.
  2. // All rights reserved.
  3. //
  4. // Author: sevenyou <sevenyou@tencent.com>
  5. // Created: 07/18/17
  6. // Description:
  7. #ifndef HTTP_SENDER_H
  8. #define HTTP_SENDER_H
  9. #pragma once
  10. #include <stdint.h>
  11. #include <map>
  12. #include <string>
  13. #include "trsf/transfer_handler.h"
  14. namespace qcloud_cos {
  15. class HttpSender {
  16. public:
  17. static int SendRequest(const SharedTransferHandler& handler,
  18. const std::string& http_method,
  19. const std::string& url_str,
  20. const std::map<std::string, std::string>& req_params,
  21. const std::map<std::string, std::string>& req_headers,
  22. const std::string& req_body,
  23. uint64_t conn_timeout_in_ms,
  24. uint64_t recv_timeout_in_ms,
  25. std::map<std::string, std::string>* resp_headers,
  26. std::string* resp_body, std::string* err_msg,
  27. bool is_check_md5 = false,
  28. bool is_verify_cert = true,
  29. const std::string& ca_location = "",
  30. const SSLCtxCallback& ssl_ctx_cb = nullptr,
  31. void *user_data = nullptr);
  32. static int SendRequest(const SharedTransferHandler& handler,
  33. const std::string& http_method,
  34. const std::string& url_str,
  35. const std::map<std::string, std::string>& req_params,
  36. const std::map<std::string, std::string>& req_headers,
  37. std::istream& is, uint64_t conn_timeout_in_ms,
  38. uint64_t recv_timeout_in_ms,
  39. std::map<std::string, std::string>* resp_headers,
  40. std::string* resp_body, std::string* err_msg,
  41. bool is_check_md5 = false,
  42. bool is_verify_cert = true,
  43. const std::string& ca_location = "",
  44. const SSLCtxCallback& ssl_ctx_cb = nullptr,
  45. void *user_data = nullptr);
  46. static int SendRequest(const SharedTransferHandler& handler,
  47. const std::string& http_method,
  48. const std::string& url_str,
  49. const std::map<std::string, std::string>& req_params,
  50. const std::map<std::string, std::string>& req_headers,
  51. std::istream& is, // 流式输入,用于传输请求正文
  52. uint64_t conn_timeout_in_ms,
  53. uint64_t recv_timeout_in_ms,
  54. std::map<std::string, std::string>* resp_headers,
  55. std::ostream& resp_stream, // 流式输出,用于接收响应正文
  56. std::string* err_msg,
  57. bool is_check_md5 = false,
  58. bool is_verify_cert = true,
  59. const std::string& ca_location = "",
  60. const SSLCtxCallback& ssl_ctx_cb = nullptr,
  61. void *user_data = nullptr,
  62. const char *req_body_buf = nullptr, // 可选的缓冲区
  63. size_t req_body_len = 0);
  64. static int SendRequest(const SharedTransferHandler& handler,
  65. const std::string& http_method,
  66. const std::string& url_str,
  67. const std::map<std::string, std::string>& req_params,
  68. const std::map<std::string, std::string>& req_headers,
  69. const std::string& req_body, // 字符串输入,用于传输请求正文
  70. uint64_t conn_timeout_in_ms,
  71. uint64_t recv_timeout_in_ms,
  72. std::map<std::string, std::string>* resp_headers,
  73. std::string* xml_err_str, // 额外的错误信息, 用于响应返回非 2xx 错误码时, 传输报错响应信息
  74. std::ostream& resp_stream, // 流式输出, 用于传输响应正文
  75. std::string* err_msg,
  76. uint64_t* real_byte, // 实际接收字节数
  77. bool is_check_md5 = false,
  78. bool is_verify_cert = true,
  79. const std::string& ca_location = "",
  80. const SSLCtxCallback& ssl_ctx_cb = nullptr,
  81. void *user_data = nullptr);
  82. };
  83. } // namespace qcloud_cos
  84. #endif // HTTP_SENDER_H