http_response.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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();
  21. ~response();
  22. void init(reqpack* rp);
  23. bool send(const char* buf, size_t buf_len, ushort stateNum = 200, const std::string& stateDesc = "OK");
  24. bool send(const ylib::buffer& value, ushort stateNum = 200, const std::string& stateDesc = "OK");
  25. bool send(const std::string& value, ushort stateNum = 200, const std::string& stateDesc = "OK");
  26. bool send(const ylib::json& json, ushort stateNum = 200, const std::string& stateDesc = "OK");
  27. bool send_file(const std::string& filepath, int32 downbaud = -1, ushort stateNum = 200, const std::string& stateDesc = "OK");
  28. std::map<std::string, std::string>* headers();
  29. bool redirect(const std::string& filepath, bool MovedPermanently = false);
  30. bool forward(const std::string& filepath);
  31. public:
  32. ylib::json sjson;
  33. private:
  34. bool filecache(const uint64& last_modify_time);
  35. bool fileoffset(long filesize, long& start, long& len);
  36. private:
  37. std::map<std::string, std::string> m_headers;
  38. bool m_response;
  39. network::http::reqpack* m_reqpack;
  40. };
  41. }
  42. }
  43. }
  44. #endif