http_reqpack.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /// <param name="msg_type"></param>
  34. /// <param name="ws_msg"></param>
  35. reqpack(const std::string& url, const std::string& host, ylib::buffer data, uint64 connid, network::http::server* server,network::http::website* website, network::http::message_type msg_type, std::shared_ptr<network::http::websocket_message> ws_msg = nullptr);
  36. ~reqpack();
  37. /// <summary>
  38. /// 请求对象
  39. /// </summary>
  40. /// <returns></returns>
  41. const std::shared_ptr<network::http::request>& request();
  42. /// <summary>
  43. /// 回复对象
  44. /// </summary>
  45. /// <returns></returns>
  46. const std::shared_ptr<network::http::response>& response();
  47. /// <summary>
  48. /// httpserver
  49. /// </summary>
  50. /// <returns></returns>
  51. network::http::server* server() { return m_server; }
  52. /// <summary>
  53. /// 连接ID
  54. /// </summary>
  55. /// <returns></returns>
  56. uint64 connid() { return m_connid; }
  57. /// <summary>
  58. /// 请求完整URL
  59. /// </summary>
  60. /// <returns></returns>
  61. std::string url() { return m_url; }
  62. /// <summary>
  63. /// 请求路径
  64. /// </summary>
  65. /// <returns></returns>
  66. std::string filepath() { return m_filepath; }
  67. /// <summary>
  68. /// 请求主机
  69. /// </summary>
  70. /// <returns></returns>
  71. std::string host() { return m_host; }
  72. /// <summary>
  73. /// 请求数据
  74. /// </summary>
  75. /// <returns></returns>
  76. ylib::buffer& body() { return m_data; }
  77. /// <summary>
  78. /// 附加数据
  79. /// </summary>
  80. /// <returns></returns>
  81. ylib::json& extra() { return m_extra; }
  82. /// <summary>
  83. /// 消息类型
  84. /// </summary>
  85. /// <returns></returns>
  86. network::http::message_type msg_type() { return m_msg_type; }
  87. /// <summary>
  88. /// WebSocket消息
  89. /// </summary>
  90. /// <returns></returns>
  91. const std::shared_ptr<network::http::websocket_message>& ws_msg() { return m_ws_msg; }
  92. /// <summary>
  93. /// 创建时间
  94. /// </summary>
  95. /// <returns></returns>
  96. int64 create_time() { return m_create_time; }
  97. /// <summary>
  98. /// 设置为关闭连接包
  99. /// </summary>
  100. void set_close() { m_is_close = true; }
  101. bool is_close() { return m_is_close; }
  102. private:
  103. // 请求
  104. std::shared_ptr<network::http::request> m_request;
  105. // 回复
  106. std::shared_ptr<network::http::response> m_response;
  107. // WebSocket消息
  108. std::shared_ptr<network::http::websocket_message> m_ws_msg;
  109. // httpserver
  110. network::http::server* m_server = nullptr;
  111. // 请求地址
  112. std::string m_url;
  113. // 请求路径
  114. std::string m_filepath;
  115. // 请求主机
  116. std::string m_host;
  117. // 请求数据
  118. ylib::buffer m_data;
  119. // 请求ID
  120. uint64 m_connid = 0;
  121. // 附加数据
  122. ylib::json m_extra;
  123. // 消息类型
  124. network::http::message_type m_msg_type = HTTP_SERVER_MESSAGE_TYPE_NORMAL;
  125. // 是否为关闭连接包
  126. bool m_is_close = false;
  127. // 创建时间
  128. int64 m_create_time = 0;
  129. };
  130. }
  131. }
  132. }
  133. #endif