etr / libhttpserver

C++ library for creating an embedded Rest HTTP server (and more)
GNU Lesser General Public License v2.1
884 stars 185 forks source link

Use std::function for not_found and other callbacks instead of function pointers. #282

Closed stuart-byma closed 1 year ago

stuart-byma commented 1 year ago

This would allow passing contextual information directly to the not found (or other) handler via a lambda capture. Basic function pointers only support lambdas without captures.

I imagine this would be a drop in replacement of

typedef const std::shared_ptr<http_response>(*render_ptr)(const http_request&);

with

typedef std::function<const std::shared_ptr<http_response>(const http_request &)> render_ptr;

etr commented 1 year ago

This sounds like an excellent idea. I have just kicked off the checks on your PR.