![]() |
zeep::http::controller — A base class for controllers, classes that handle a request.
// In header: <zeep/http/controller.hpp> class controller { public: // construct/copy/destruct controller(const std::string &); controller(const controller &) = delete; controller & operator=(const controller &) = delete; ~controller(); // public member functions virtual bool dispatch_request(request &, reply &); virtual bool handle_request(request &, reply &) = 0; std::string get_prefix() const; bool path_matches_prefix(const std::string &) const; std::string get_prefixless_path(const request &) const; virtual void set_server(server *); const server & get_server() const; server & get_server(); json::element get_credentials() const; std::string get_remote_address() const; bool has_role(const std::string &) const; };
This concept is inspired by the Spring way of delegating the work to controller classes. In libzeep there are two major implementations of controllers: zeep::http::rest_controller and zeep::http::soap_controller
There can be multiple controllers in a web application, each is connected to a certain prefix-path. This is the leading part of the request URI.
controller
public
construct/copy/destructcontroller(const std::string & prefix_path);constructor
Parameters: |
|
controller(const controller &) = delete;
controller & operator=(const controller &) = delete;
~controller();
controller
public member functionsvirtual bool dispatch_request(request & req, reply & rep);Calls handle_request but stores a pointer to the request first.
virtual bool handle_request(request & req, reply & rep) = 0;The pure virtual method that actually handles the request.
std::string get_prefix() const;returns the defined prefix path
bool path_matches_prefix(const std::string & path) const;return whether this uri request path matches our prefix
std::string get_prefixless_path(const request & req) const;return the path with the prefix path stripped off
virtual void set_server(server * server);bind this controller to server
const server & get_server() const;return the server object we're bound to
server & get_server();
json::element get_credentials() const;get the credentials for the current request
std::string get_remote_address() const;get the remote client address for the current request
bool has_role(const std::string & role) const;returns whether the current user has role role