http_reqpack.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include "http_define.h"
  3. #if USE_NET_HTTP_WEBSITE
  4. #include "http_server.h"
  5. #include "util/strutils.h"
  6. #include "util/time.h"
  7. namespace ylib
  8. {
  9. namespace network
  10. {
  11. namespace http
  12. {
  13. class server;
  14. class response;
  15. class request;
  16. class website;
  17. /*************************************************************************
  18. * class:请求包
  19. *************************************************************************/
  20. class reqpack
  21. {
  22. public:
  23. reqpack();
  24. ~reqpack();
  25. void init(const std::string& url, const std::string& host, const ylib::buffer& data, uint64 connid, network::http::server* server);
  26. void clear();
  27. network::http::request* request();
  28. network::http::response* response();
  29. const std::string& host()
  30. {
  31. /*获取基本请求信息*/
  32. return m_host;
  33. }
  34. network::http::method method();
  35. const std::string& filepath();
  36. void filepath(const std::string& path);
  37. network::http::server* server()
  38. {
  39. return m_server;
  40. }
  41. ylib::buffer& data()
  42. {
  43. return m_data;
  44. }
  45. const std::string& url()
  46. {
  47. return m_url;
  48. }
  49. const std::string& referrer()
  50. {
  51. return m_referrer;
  52. }
  53. const uint64& connid()
  54. {
  55. return m_connid;
  56. }
  57. network::http::website* website() {
  58. return m_website;
  59. }
  60. void website(network::http::website* website) {
  61. m_website = website;
  62. }
  63. timestamp begin_msec() {
  64. return m_begin_msec;
  65. }
  66. std::string exec_msec() {
  67. return std::to_string(time::now_msec() - m_begin_msec);
  68. }
  69. const std::string& remote() {
  70. if (m_remote_ipaddress.empty()) {
  71. ushort port;
  72. m_server->remote(connid(), m_remote_ipaddress, port);
  73. }
  74. return m_remote_ipaddress;
  75. }
  76. ylib::json& extra() { return m_extra; }
  77. private:
  78. // 请求主机
  79. std::string m_host;
  80. // 请求方式
  81. network::http::method m_method;
  82. // 请求路径
  83. std::string m_filepath;
  84. // HPSERVER
  85. network::http::server* m_server;
  86. // 转发来路
  87. std::string m_referrer;
  88. // 请求ID
  89. uint64 m_connid;
  90. // 站点
  91. network::http::website* m_website;
  92. // 接收数据
  93. ylib::buffer m_data;
  94. // URL
  95. std::string m_url;
  96. // 请求发起时间
  97. timestamp m_begin_msec;
  98. // 远程IP
  99. std::string m_remote_ipaddress;
  100. // 附加数据
  101. ylib::json m_extra;
  102. private:
  103. network::http::request* m_request;
  104. network::http::response* m_response;
  105. };
  106. }
  107. }
  108. }
  109. #endif