http_request.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. #include "http_define.h"
  3. #if USE_NET_HTTP_WEBSITE
  4. #include <string>
  5. #include <vector>
  6. #include "http_session.h"
  7. #include "http_interface.h"
  8. namespace ylib
  9. {
  10. namespace network
  11. {
  12. namespace http
  13. {
  14. class reqpack;
  15. class server;
  16. /// <summary>
  17. /// HTTP请求
  18. /// </summary>
  19. class request :public network::http::interface_
  20. {
  21. public:
  22. request(network::http::reqpack* reqpack);
  23. ~request();
  24. /// <summary>
  25. /// 取请求头
  26. /// </summary>
  27. /// <param name="name"></param>
  28. /// <param name="value"></param>
  29. /// <returns></returns>
  30. bool header(const std::string& name, std::string& value);
  31. std::vector<ylib::KeyValue<std::string, std::string>> headers();
  32. /// <summary>
  33. /// 请求动作
  34. /// </summary>
  35. /// <returns></returns>
  36. std::string method();
  37. /// <summary>
  38. /// 取请求路径
  39. /// </summary>
  40. /// <returns></returns>
  41. std::string filepath();
  42. /// <summary>
  43. /// 取请求主机
  44. /// </summary>
  45. /// <returns></returns>
  46. std::string host();
  47. /// <summary>
  48. /// session
  49. /// </summary>
  50. /// <param name="session_id"></param>
  51. /// <returns></returns>
  52. network::http::session& session(const std::string& session_id);
  53. network::http::reqpack* reqpack();
  54. /// <summary>
  55. /// 远程信息
  56. /// </summary>
  57. /// <returns></returns>
  58. ylib::AddressPort remote();
  59. /// <summary>
  60. /// 取请求参数
  61. /// </summary>
  62. /// <param name="name"></param>
  63. /// <param name="value"></param>
  64. /// <returns></returns>
  65. bool get_url_param(const std::string& name,std::string& value);
  66. bool get_body_param(const std::string& name, std::string& value);
  67. std::shared_ptr<std::map<std::string, std::string>>& url_param();
  68. std::shared_ptr<std::map<std::string, std::string>>& body_param();
  69. /// <summary>
  70. /// 表单数据
  71. /// </summary>
  72. /// <returns></returns>
  73. const std::shared_ptr<std::vector<network::http::multipart>>& multipart();
  74. /// <summary>
  75. /// 是否为请求类型
  76. /// </summary>
  77. /// <returns></returns>
  78. bool content_type(std::string type_name);
  79. /// <summary>
  80. /// Body
  81. /// </summary>
  82. /// <returns></returns>
  83. ylib::buffer& body();
  84. private:
  85. // reqpack
  86. network::http::reqpack* m_reqpack = nullptr;
  87. // session
  88. network::http::session m_session;
  89. // 请求动作
  90. std::string m_method;
  91. private:
  92. // 请求参数[URL]
  93. std::shared_ptr<std::map<std::string, std::string>> m_url_param;
  94. // 请求参数[BODY]
  95. std::shared_ptr<std::map<std::string, std::string>> m_body_param;
  96. // FORM数据
  97. std::shared_ptr<std::vector<network::http::multipart>> m_form;
  98. };
  99. }
  100. }
  101. }
  102. #endif