http_response.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include "http_define.h"
  3. #if USE_NET_HTTP_WEBSITE
  4. #include <string>
  5. #include <vector>
  6. #include <list>
  7. #include "http_header.h"
  8. #include "http_interface.h"
  9. namespace ylib
  10. {
  11. namespace network
  12. {
  13. namespace http
  14. {
  15. class server;
  16. class reqpack;
  17. class response :public network::http::interface_
  18. {
  19. public:
  20. response(network::http::reqpack* reqpack);
  21. ~response();
  22. bool send(const char* buf, size_t buf_len, ushort stateNum = 200, const std::string& stateDesc = "OK");
  23. bool send(const ylib::buffer& value, ushort stateNum = 200, const std::string& stateDesc = "OK");
  24. bool send(const std::string& value, ushort stateNum = 200, const std::string& stateDesc = "OK");
  25. bool send(const ylib::json& json, ushort stateNum = 200, const std::string& stateDesc = "OK");
  26. bool send_file(const std::string& filepath, int32 downbaud = -1, ushort stateNum = 200, const std::string& stateDesc = "OK");
  27. std::map<std::string, std::string>* headers();
  28. bool redirect(const std::string& filepath, bool MovedPermanently = false);
  29. bool forward(const std::string& filepath);
  30. public:
  31. ylib::json sjson;
  32. private:
  33. bool filecache(const uint64& last_modify_time);
  34. bool fileoffset(long filesize, long& start, long& len);
  35. private:
  36. std::map<std::string, std::string> m_headers;
  37. bool m_response = false;
  38. network::http::reqpack* m_reqpack = nullptr;
  39. };
  40. }
  41. }
  42. }
  43. #endif