response.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // MIT License
  2. // Copyright(c) 2024 FastWeb - fwlua.com - nianhua
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files(the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions :
  9. // The above copyright notice and this permission notice shall be included in all
  10. // copies or substantial portions of the Software.
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
  14. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. // SOFTWARE.
  18. // ## Additional Terms for Commercial Use
  19. // This software is licensed for personal, educational, and non - commercial use.
  20. // For commercial use or use within a company, organization, or institution, a
  21. // separate commercial license is required.To obtain a commercial license,
  22. // please contact
  23. // EMail:1585346868@qq.com
  24. // QQ:1585346868
  25. #include "response.h"
  26. #include "net/http_reqpack.h"
  27. module::response::response(network::http::response* response) :m_response(response)
  28. {
  29. }
  30. module::response::~response()
  31. {
  32. }
  33. void module::response::regist(sol::state* lua)
  34. {
  35. // 绑定 Request 类到 Lua
  36. lua->new_usertype<module::response>("module_response",
  37. "send_data", &module::response::send_data,
  38. "send", &module::response::send,
  39. "send_file", &module::response::send_file,
  40. "header", &module::response::header,
  41. "redirect", &module::response::redirect,
  42. "forward", &module::response::forward
  43. );
  44. }
  45. bool module::response::send_data(const char* buf, size_t buf_len, ushort stateNum, const std::string& stateDesc)
  46. {
  47. return m_response->send(buf, buf_len, stateNum, stateDesc);
  48. }
  49. bool module::response::send(const std::string& value)
  50. {
  51. return m_response->send(value);
  52. }
  53. bool module::response::sendex(const std::string& value, ushort stateNum, const std::string& stateDesc)
  54. {
  55. return m_response->send(value, stateNum, stateDesc);
  56. }
  57. bool module::response::send_file(const std::string& filepath, int32 downbaud, ushort stateNum, const std::string& stateDesc)
  58. {
  59. return m_response->send_file(filepath, downbaud, stateNum, stateDesc);
  60. }
  61. bool module::response::redirect(const std::string& filepath, bool MovedPermanently)
  62. {
  63. return m_response->redirect(filepath, MovedPermanently);
  64. }
  65. bool module::response::forward(const std::string& filepath)
  66. {
  67. return m_response->forward(filepath);
  68. }
  69. void module::response::header(const std::string& name, const std::string& value)
  70. {
  71. m_response->headers()->emplace(name, value);
  72. }