http_reqpack.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #pragma once
  2. #include "http_define.h"
  3. #if USE_NET_HTTP_WEBSITE
  4. #include "http_server.h"
  5. #include "http_interface.h"
  6. #include "util/strutils.h"
  7. #include "util/time.h"
  8. namespace ylib
  9. {
  10. namespace network
  11. {
  12. namespace http
  13. {
  14. class server;
  15. class response;
  16. class request;
  17. class website;
  18. /// <summary>
  19. /// 请求包
  20. /// </summary>
  21. class reqpack:public network::http::interface_
  22. {
  23. public:
  24. /// <summary>
  25. /// 构造函数
  26. /// </summary>
  27. /// <param name="url"></param>
  28. /// <param name="host"></param>
  29. /// <param name="data"></param>
  30. /// <param name="connid"></param>
  31. /// <param name="server"></param>
  32. /// <param name="website"></param>
  33. reqpack(const std::string& url, const std::string& host, const ylib::buffer& data, uint64 connid, network::http::server* server,network::http::website* website);
  34. ~reqpack();
  35. /// <summary>
  36. /// 请求对象
  37. /// </summary>
  38. /// <returns></returns>
  39. const std::shared_ptr<network::http::request>& request();
  40. /// <summary>
  41. /// 回复对象
  42. /// </summary>
  43. /// <returns></returns>
  44. const std::shared_ptr<network::http::response>& response();
  45. /// <summary>
  46. /// httpserver
  47. /// </summary>
  48. /// <returns></returns>
  49. network::http::server* server() { return m_server; }
  50. /// <summary>
  51. /// 连接ID
  52. /// </summary>
  53. /// <returns></returns>
  54. uint64 connid() { return m_connid; }
  55. /// <summary>
  56. /// 请求完整URL
  57. /// </summary>
  58. /// <returns></returns>
  59. std::string url() { return m_url; }
  60. /// <summary>
  61. /// 请求路径
  62. /// </summary>
  63. /// <returns></returns>
  64. std::string filepath() { return m_filepath; }
  65. /// <summary>
  66. /// 请求主机
  67. /// </summary>
  68. /// <returns></returns>
  69. std::string host() { return m_host; }
  70. /// <summary>
  71. /// 请求数据
  72. /// </summary>
  73. /// <returns></returns>
  74. ylib::buffer& body() { return m_data; }
  75. /// <summary>
  76. /// 附加数据
  77. /// </summary>
  78. /// <returns></returns>
  79. ylib::json& extra() { return m_extra; }
  80. private:
  81. // 请求
  82. std::shared_ptr<network::http::request> m_request;
  83. // 回复
  84. std::shared_ptr<network::http::response> m_response;
  85. // httpserver
  86. network::http::server* m_server = nullptr;
  87. // 请求地址
  88. std::string m_url;
  89. // 请求路径
  90. std::string m_filepath;
  91. // 请求主机
  92. std::string m_host;
  93. // 请求数据
  94. ylib::buffer m_data;
  95. // 请求ID
  96. uint64 m_connid = 0;
  97. // 附加数据
  98. ylib::json m_extra;
  99. };
  100. }
  101. }
  102. }
  103. #endif