| 742 | } // namespace detail |
| 743 | |
| 744 | class Server { |
| 745 | public: |
| 746 | using Handler = std::function<void(const Request &, Response &)>; |
| 747 | |
| 748 | using ExceptionHandler = |
| 749 | std::function<void(const Request &, Response &, std::exception_ptr ep)>; |
| 750 | |
| 751 | enum class HandlerResponse { |
| 752 | Handled, |
| 753 | Unhandled, |
| 754 | }; |
| 755 | using HandlerWithResponse = |
| 756 | std::function<HandlerResponse(const Request &, Response &)>; |
| 757 | |
| 758 | using HandlerWithContentReader = std::function<void( |
| 759 | const Request &, Response &, const ContentReader &content_reader)>; |
| 760 | |
| 761 | using Expect100ContinueHandler = |
| 762 | std::function<int(const Request &, Response &)>; |
| 763 | |
| 764 | Server(); |
| 765 | |
| 766 | virtual ~Server(); |
| 767 | |
| 768 | virtual bool is_valid() const; |
| 769 | |
| 770 | Server &Get(const std::string &pattern, Handler handler); |
| 771 | Server &Post(const std::string &pattern, Handler handler); |
| 772 | Server &Post(const std::string &pattern, HandlerWithContentReader handler); |
| 773 | Server &Put(const std::string &pattern, Handler handler); |
| 774 | Server &Put(const std::string &pattern, HandlerWithContentReader handler); |
| 775 | Server &Patch(const std::string &pattern, Handler handler); |
| 776 | Server &Patch(const std::string &pattern, HandlerWithContentReader handler); |
| 777 | Server &Delete(const std::string &pattern, Handler handler); |
| 778 | Server &Delete(const std::string &pattern, HandlerWithContentReader handler); |
| 779 | Server &Options(const std::string &pattern, Handler handler); |
| 780 | |
| 781 | bool set_base_dir(const std::string &dir, |
| 782 | const std::string &mount_point = std::string()); |
| 783 | bool set_mount_point(const std::string &mount_point, const std::string &dir, |
| 784 | Headers headers = Headers()); |
| 785 | bool remove_mount_point(const std::string &mount_point); |
| 786 | Server &set_file_extension_and_mimetype_mapping(const std::string &ext, |
| 787 | const std::string &mime); |
| 788 | Server &set_default_file_mimetype(const std::string &mime); |
| 789 | Server &set_file_request_handler(Handler handler); |
| 790 | |
| 791 | Server &set_error_handler(HandlerWithResponse handler); |
| 792 | Server &set_error_handler(Handler handler); |
| 793 | Server &set_exception_handler(ExceptionHandler handler); |
| 794 | Server &set_pre_routing_handler(HandlerWithResponse handler); |
| 795 | Server &set_post_routing_handler(Handler handler); |
| 796 | |
| 797 | Server &set_expect_100_continue_handler(Expect100ContinueHandler handler); |
| 798 | Server &set_logger(Logger logger); |
| 799 | |
| 800 | Server &set_address_family(int family); |
| 801 | Server &set_tcp_nodelay(bool on); |