http_request.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #pragma once
  2. #include "http_define.h"
  3. #if USE_NET_HTTP_WEBSITE
  4. #include <string>
  5. #include <vector>
  6. #include "http_interface.h"
  7. namespace ylib
  8. {
  9. namespace network
  10. {
  11. namespace http
  12. {
  13. class reqpack;
  14. class server;
  15. /// <summary>
  16. /// HTTP请求
  17. /// </summary>
  18. class request :public network::http::interface_
  19. {
  20. public:
  21. request(network::http::reqpack* reqpack);
  22. ~request();
  23. /// <summary>
  24. /// 取请求头
  25. /// </summary>
  26. /// <param name="name"></param>
  27. /// <param name="value"></param>
  28. /// <returns></returns>
  29. bool header(const std::string& name, std::string& value);
  30. std::vector<ylib::KeyValue<std::string, std::string>> headers();
  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. network::http::reqpack* reqpack();
  47. /// <summary>
  48. /// 远程信息
  49. /// </summary>
  50. /// <returns></returns>
  51. ylib::AddressPort remote();
  52. /// <summary>
  53. /// 取请求参数
  54. /// </summary>
  55. /// <param name="name"></param>
  56. /// <param name="value"></param>
  57. /// <returns></returns>
  58. bool get_url_param(const std::string& name,std::string& value);
  59. bool get_body_param(const std::string& name, std::string& value);
  60. std::shared_ptr<std::map<std::string, std::string>>& url_param();
  61. std::shared_ptr<std::map<std::string, std::string>>& body_param();
  62. /// <summary>
  63. /// 表单数据
  64. /// </summary>
  65. /// <returns></returns>
  66. const std::shared_ptr<std::vector<network::http::multipart>>& multipart();
  67. /// <summary>
  68. /// 是否为请求类型
  69. /// </summary>
  70. /// <returns></returns>
  71. bool content_type(std::string type_name);
  72. /// <summary>
  73. /// Body
  74. /// </summary>
  75. /// <returns></returns>
  76. ylib::buffer& body();
  77. private:
  78. // reqpack
  79. network::http::reqpack* m_reqpack = nullptr;
  80. // 请求动作
  81. std::string m_method;
  82. private:
  83. // 请求参数[URL]
  84. std::shared_ptr<std::map<std::string, std::string>> m_url_param;
  85. // 请求参数[BODY]
  86. std::shared_ptr<std::map<std::string, std::string>> m_body_param;
  87. // FORM数据
  88. std::shared_ptr<std::vector<network::http::multipart>> m_form;
  89. };
  90. }
  91. }
  92. }
  93. #endif