-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invert set_pre_routing_handler return value semantics #839
Comments
@00ff0000red, in fact, I intentionally made the behavior. The content reader for Instead, the pre routing handler is called only once. I still feel that the current behavior is more natural for me. But if most of users think differently, I don't mind reconsidering this matter. But first, I would like to do more research how other http libraries and frameworks are treating it. Anyway, thanks for bringing this thing up! |
@yhirose I think I understand the root of the problem, it's that booleans themselves don't have any semantic meaning on their own. In a situation like this, I think that an enum would make much more sense, as it would attach a name to the value, and associate semantics with it. I'm thinking something like so: enum class PreHandlerResponse : bool {
Handled,
Unhandled
}; Updating the example in the README, we have this: using httplib::PreHandlerResponse;
svr.set_pre_routing_handler([](const auto& req, auto& res) -> PreHandlerResponse {
if (req.path == "/hello") {
res.set_content("world", "text/html");
return PreHandlerResponse::Handled; // This request is handled
}
return PreHandlerResponse::Unhandled; // Let the router handle this request
}); IMO, that makes that snippet much more readable, as opposed to the "random" I believe that an enum would nicely solve this situation, removing ambiguity and the differences in our interpretations, what do you think? |
@00ff0000red, sounds very good. I implemented it. Thanks! |
@yhirose CI is currently failing after that commit. |
Currently, I feel like
Sever::set_pre_routing_handler
's return value is inverted, especially when compared to howServer::Get
and such operate.true
regularly means to continue the process, whilefalse
means to cancel it, butset_pre_routing_handler
does the opposite;true
cancels the process,false
continues on to the "normal" handler.Technicially, this would be a breaking change, but since it's been here for only 15 days, maybe it wouldn't be too late?
The text was updated successfully, but these errors were encountered: