libzeep

PrevUpHomeNext

Class controller

zeep::http::controller — A base class for controllers, classes that handle a request.

Synopsis

// 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(boost::asio::ip::tcp::socket &, 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(basic_server *);
  const basic_server & get_server() const;
  basic_server & get_server();
  json::element get_credentials() const;
  std::string get_remote_address() const;
  bool has_role(const std::string &) const;
  std::string get_header(const char *) const;
};

Description

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/destruct

  1. controller(const std::string & prefix_path);
    constructor

    Parameters:

    prefix_path

    The prefix path this controller is bound to

  2. controller(const controller &) = delete;
  3. controller & operator=(const controller &) = delete;
  4. ~controller();

controller public member functions

  1. virtual bool 
    dispatch_request(boost::asio::ip::tcp::socket & socket, request & req, 
                     reply & rep);
    Calls handle_request but stores a pointer to the request first.
  2. virtual bool handle_request(request & req, reply & rep) = 0;
    The pure virtual method that actually handles the request.
  3. std::string get_prefix() const;
    returns the defined prefix path
  4. bool path_matches_prefix(const std::string & path) const;
    return whether this uri request path matches our prefix
  5. std::string get_prefixless_path(const request & req) const;
    return the path with the prefix path stripped off
  6. virtual void set_server(basic_server * server);
    bind this controller to server
  7. const basic_server & get_server() const;
    return the server object we're bound to
  8. basic_server & get_server();
  9. json::element get_credentials() const;
    get the credentials for the current request
  10. std::string get_remote_address() const;
    get the remote client address for the current request
  11. bool has_role(const std::string & role) const;
    returns whether the current user has role role
  12. std::string get_header(const char * name) const;
    return a specific header line from the original request

PrevUpHomeNext