http_request.h 3.6 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. /// <summary>
  32. /// 请求动作
  33. /// </summary>
  34. /// <returns></returns>
  35. std::string method();
  36. /// <summary>
  37. /// 取请求路径
  38. /// </summary>
  39. /// <returns></returns>
  40. std::string filepath();
  41. /// <summary>
  42. /// 取请求主机
  43. /// </summary>
  44. /// <returns></returns>
  45. std::string host();
  46. /// <summary>
  47. /// session
  48. /// </summary>
  49. /// <param name="session_id"></param>
  50. /// <returns></returns>
  51. network::http::session& session(const std::string& session_id);
  52. network::http::reqpack* reqpack();
  53. /// <summary>
  54. /// 远程信息
  55. /// </summary>
  56. /// <returns></returns>
  57. ylib::AddressPort remote();
  58. /// <summary>
  59. /// 取请求参数
  60. /// </summary>
  61. /// <param name="name"></param>
  62. /// <param name="value"></param>
  63. /// <returns></returns>
  64. bool get_url_param(const std::string& name,std::string& value);
  65. bool get_body_param(const std::string& name, std::string& value);
  66. std::shared_ptr<std::map<std::string, std::string>>& url_param() { return m_url_param; }
  67. std::shared_ptr<std::map<std::string, std::string>>& body_param() { return m_body_param; }
  68. /// <summary>
  69. /// 表单数据
  70. /// </summary>
  71. /// <returns></returns>
  72. const std::shared_ptr<std::vector<network::http::multipart>>& multipart();
  73. /// <summary>
  74. /// 是否为请求类型
  75. /// </summary>
  76. /// <returns></returns>
  77. bool content_type(std::string type_name);
  78. /// <summary>
  79. /// Body
  80. /// </summary>
  81. /// <returns></returns>
  82. ylib::buffer& body();
  83. private:
  84. // reqpack
  85. network::http::reqpack* m_reqpack = nullptr;
  86. // session
  87. network::http::session m_session;
  88. // 请求动作
  89. std::string m_method;
  90. private:
  91. // 请求参数[URL]
  92. std::shared_ptr<std::map<std::string, std::string>> m_url_param;
  93. // 请求参数[BODY]
  94. std::shared_ptr<std::map<std::string, std::string>> m_body_param;
  95. // FORM数据
  96. std::shared_ptr<std::vector<network::http::multipart>> m_form;
  97. };
  98. }
  99. }
  100. }
  101. #endif