http_reqpack.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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, const 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. void set_close() { m_is_close = true; }
  96. bool is_close() { return m_is_close; }
  97. private:
  98. // 请求
  99. std::shared_ptr<network::http::request> m_request;
  100. // 回复
  101. std::shared_ptr<network::http::response> m_response;
  102. // WebSocket消息
  103. std::shared_ptr<network::http::websocket_message> m_ws_msg;
  104. // httpserver
  105. network::http::server* m_server = nullptr;
  106. // 请求地址
  107. std::string m_url;
  108. // 请求路径
  109. std::string m_filepath;
  110. // 请求主机
  111. std::string m_host;
  112. // 请求数据
  113. ylib::buffer m_data;
  114. // 请求ID
  115. uint64 m_connid = 0;
  116. // 附加数据
  117. ylib::json m_extra;
  118. // 消息类型
  119. network::http::message_type m_msg_type = HTTP_SERVER_MESSAGE_TYPE_NORMAL;
  120. // 是否为关闭连接包
  121. bool m_is_close = false;
  122. };
  123. }
  124. }
  125. }
  126. #endif