1
0
mirror of synced 2025-04-21 22:25:55 +03:00

Merge branch 'HerrCai0907-fix'

This commit is contained in:
yhirose 2024-04-11 22:30:00 -04:00
commit 2064462c35

View File

@ -871,8 +871,13 @@ public:
Server &set_default_file_mimetype(const std::string &mime); Server &set_default_file_mimetype(const std::string &mime);
Server &set_file_request_handler(Handler handler); Server &set_file_request_handler(Handler handler);
Server &set_error_handler(HandlerWithResponse handler); template <class ErrorHandlerFunc>
Server &set_error_handler(Handler handler); Server &set_error_handler(ErrorHandlerFunc &&handler) {
return set_error_handler_core(
std::forward<ErrorHandlerFunc>(handler),
std::is_convertible<ErrorHandlerFunc, HandlerWithResponse>{});
}
Server &set_exception_handler(ExceptionHandler handler); Server &set_exception_handler(ExceptionHandler handler);
Server &set_pre_routing_handler(HandlerWithResponse handler); Server &set_pre_routing_handler(HandlerWithResponse handler);
Server &set_post_routing_handler(Handler handler); Server &set_post_routing_handler(Handler handler);
@ -943,6 +948,9 @@ private:
static std::unique_ptr<detail::MatcherBase> static std::unique_ptr<detail::MatcherBase>
make_matcher(const std::string &pattern); make_matcher(const std::string &pattern);
Server &set_error_handler_core(HandlerWithResponse handler, std::true_type);
Server &set_error_handler_core(Handler handler, std::false_type);
socket_t create_server_socket(const std::string &host, int port, socket_t create_server_socket(const std::string &host, int port,
int socket_flags, int socket_flags,
SocketOptions socket_options) const; SocketOptions socket_options) const;
@ -5808,12 +5816,14 @@ inline Server &Server::set_file_request_handler(Handler handler) {
return *this; return *this;
} }
inline Server &Server::set_error_handler(HandlerWithResponse handler) { inline Server &Server::set_error_handler_core(HandlerWithResponse handler,
std::true_type) {
error_handler_ = std::move(handler); error_handler_ = std::move(handler);
return *this; return *this;
} }
inline Server &Server::set_error_handler(Handler handler) { inline Server &Server::set_error_handler_core(Handler handler,
std::false_type) {
error_handler_ = [handler](const Request &req, Response &res) { error_handler_ = [handler](const Request &req, Response &res) {
handler(req, res); handler(req, res);
return HandlerResponse::Handled; return HandlerResponse::Handled;