http_interceptor.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include "define.h"
  3. #if USE_NET_HTTP_WEBSITE
  4. #include <regex>
  5. #include <functional>
  6. #include "ynet/http_interface.h"
  7. #include "yutil/array.hpp"
  8. namespace ylib
  9. {
  10. namespace network
  11. {
  12. namespace http
  13. {
  14. class reqpack;
  15. struct interceptor_info {
  16. std::regex express;
  17. std::string express_string;
  18. std::function<bool(network::http::reqpack* rp)> callback;
  19. };
  20. /******************************************************
  21. * class:拦截器
  22. ******************************************************/
  23. class interceptor :public ylib::error_base, public network::http::interface_
  24. {
  25. public:
  26. interceptor();
  27. ~interceptor();
  28. size_t add(const std::string& regex_express, std::function<bool(network::http::reqpack* rp)> callback);
  29. void remove(size_t index);
  30. bool trigger(const std::string& url, network::http::reqpack* rp);
  31. private:
  32. ylib::nolock_array<interceptor_info*> m_array;
  33. };
  34. }
  35. }
  36. }
  37. #endif