http_request.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * request.h
  3. *
  4. * Created on: 2021年8月16日
  5. * Author: pengzc
  6. */
  7. #ifndef JNI_HTTP_REQUEST_H_
  8. #define JNI_HTTP_REQUEST_H_
  9. #include <string>
  10. #include <map>
  11. namespace base {
  12. class HttpClient;
  13. class HttpRequest {
  14. public:
  15. /**
  16. * GET / POST
  17. */
  18. HttpRequest(const std::string& method, const std::string& url,
  19. const std::string& body);
  20. virtual ~HttpRequest();
  21. public:
  22. typedef struct {
  23. double totalTime;
  24. double nameLookupTime;
  25. double connectTime;
  26. double appConnectTime;
  27. double preTransferTime;
  28. double startTransferTime;
  29. double redirectTime;
  30. int redirectCount;
  31. } RequestInfo;
  32. typedef struct {
  33. std::string baseUrl;
  34. int timeout;
  35. bool followRedirects;
  36. int maxRedirects;
  37. bool noSignal;
  38. struct {
  39. std::string username;
  40. std::string password;
  41. } basicAuth;
  42. std::string certPath;
  43. std::string certType;
  44. std::string keyPath;
  45. std::string keyPassword;
  46. std::string customUserAgent;
  47. std::string uriProxy;
  48. RequestInfo lastRequest;
  49. } Info;
  50. typedef std::map<std::string, std::string> Multiparts;
  51. // Instance configuration methods
  52. // configure basic auth
  53. void SetBasicAuth(const std::string& username,
  54. const std::string& password);
  55. // append additional headers
  56. HttpRequest& AppendHeader(const std::string& key,
  57. const std::string& value);
  58. //Header Content-Type
  59. HttpRequest& ContentType(const std::string& content_type);
  60. //Multipart/form data
  61. HttpRequest& AppendPart(const std::string& name, const std::string& value);
  62. private:
  63. friend class HttpClient;
  64. std::string method_;
  65. std::string url_;
  66. std::string body_;
  67. typedef std::map<std::string, std::string> HeaderFields;
  68. HeaderFields header;
  69. bool followRedirects;
  70. int maxRedirects;
  71. struct {
  72. std::string username;
  73. std::string password;
  74. } basicAuth;
  75. Multiparts multiparts_;
  76. };
  77. } /* namespace base */
  78. #endif /* JNI_HTTP_REQUEST_H_ */