![]() |
zeep::http::server — The libzeep HTTP server implementation. Originally based on example code found in boost::asio.
// In header: <zeep/http/server.hpp> class server { public: // construct/copy/destruct server(); server(const std::string &); server(security_context *); server(security_context *, const std::string &); server(const server &) = delete; server & operator=(const server &) = delete; ~server(); // public member functions security_context & get_security_context(); bool has_security_context() const; void set_context_name(const std::string &); std::string get_context_name() const; void add_controller(controller *); void add_error_handler(error_handler *); void set_template_processor(basic_template_processor *); basic_template_processor & get_template_processor(); const basic_template_processor & get_template_processor() const; bool has_template_processor() const; virtual void bind(const std::string &, unsigned short); virtual void run(int); virtual void stop(); void set_log_forwarded(bool); std::string get_address() const; unsigned short get_port() const; boost::asio::io_service & get_io_service(); // public static functions static std::ostream & get_log(); // protected member functions virtual void log_request(const std::string &, const request &, const reply &, const boost::posix_time::ptime &, const std::string &, const std::string &, const std::string &) noexcept; // private member functions virtual void handle_request(boost::asio::ip::tcp::socket &, request &, reply &); void handle_accept(boost::system::error_code); };
The server class is a simple, stand alone HTTP server. Call bind to make it listen to an address/port combination. Add controller classes to do the actual work. These controllers will be tried in the order at which they were added to see if they want to process a request.
server
public
construct/copy/destructserver();Simple server, no security, no template processor.
server(const std::string & docroot);Simple server, no security, create default template processor with docroot.
server(security_context * s_ctxt);server with a security context for limited access
server(security_context * s_ctxt, const std::string & docroot);server with a security context for limited access, create default template processor with docroot
server(const server &) = delete;
server & operator=(const server &) = delete;
~server();
server
public member functionssecurity_context & get_security_context();Get the security context provided in the constructor.
bool has_security_context() const;Test if a security context was provided in the constructor.
void set_context_name(const std::string & context_name);Set the context_name.
The context name is used in constructing relative URL's that start with a forward slash
std::string get_context_name() const;Get the context_name.
The context name is used in constructing relative URL's that start with a forward slash
void add_controller(controller * c);Add controller to the list of controllers.
When a request is received, the list of controllers get a chance of handling it, in the order of which they were added to this server. If none of the controller handle the request the not_found error is returned.
void add_error_handler(error_handler * eh);Add an error handler.
Errors are handled by the error handler list. The last added handler is called first.
void set_template_processor(basic_template_processor * template_processor);Set the template processor.
A template processor handles loading templates and processing the contents.
basic_template_processor & get_template_processor();Get the template processor.
A template processor handles loading templates and processing the contents. This will throw if the processor has not been set yet.
const basic_template_processor & get_template_processor() const;Get the template processor.
A template processor handles loading templates and processing the contents. This will throw if the processor has not been set yet.
bool has_template_processor() const;returns whether template processor has been set
virtual void bind(const std::string & address, unsigned short port);Bind the server to address address and port port.
virtual void run(int nr_of_threads);Run as many as nr_of_threads threads simultaneously.
virtual void stop();Stop all threads and stop listening.
void set_log_forwarded(bool v);log_forwarded tells the HTTP server to use the last entry in X-Forwarded-For as client log entry
std::string get_address() const;returns the address as specified in bind
unsigned short get_port() const;returns the port as specified in bind
boost::asio::io_service & get_io_service();get_io_service has to be public since we need it to call notify_fork from child code