Google APIs Client Library for C++
|
A minimal abstract interface for embedded webservers. More...
#include "client/util/abstract_webserver.h"
Public Types | |
typedef ResultCallback1 < util::Status, WebServerRequest * > | PathHandler |
Used to register a callback on particular URIs or trees. | |
Public Member Functions | |
AbstractWebServer (int port) | |
Constructs an http server on the given port. | |
virtual | ~AbstractWebServer () |
Standard destructor. | |
int | port () const |
Returns the port bound in the constructor. | |
util::Status | Startup () |
Starts the server. | |
void | Shutdown () |
Stops the server. | |
string | MakeEndpointUrl (bool use_localhost, const StringPiece &path) const |
Returns URL into this server for the given path. | |
void | AddPathHandler (const string &path, PathHandler *handler) |
Inject handler for path. | |
PathHandler * | FindPathHandler (WebServerRequest *request) const |
Looks up added PathHandler that matches path. | |
virtual string | url_protocol () const |
Returns the protocol part of the url used by this webserver (e.g. | |
Protected Member Functions | |
virtual util::Status | DoStartup ()=0 |
virtual void | DoShutdown ()=0 |
virtual util::Status | DoHandleRequest (WebServerRequest *request) |
Handles inbound request. |
A minimal abstract interface for embedded webservers.
This is only an abstract interface. You must supply your own implementation and use this class to adapt it. The interface is only intended to provide some library code and sample code that integrate with an embedded web server without explicitly depending on any particular implementation.
Note that this interface does not accomodate POST requests at this time, but the library does not need it as a client -- this abstractionis not intended to be used for implementing cloud services.
typedef ResultCallback1< util::Status, WebServerRequest*> PathHandler |
Used to register a callback on particular URIs or trees.
[in] | request | for the request being processed. |
AbstractWebServer | ( | int | port | ) | [explicit] |
Constructs an http server on the given port.
[in] | port | Should be non-0. |
virtual ~AbstractWebServer | ( | ) | [virtual] |
Standard destructor.
void AddPathHandler | ( | const string & | path, |
PathHandler * | handler | ||
) |
Inject handler for path.
[in] | path | The path to intercept with this handler. |
[in] | handler | A repeatable callback. Ownership is passed. |
This is called by the default DoHandleUrl method.
virtual util::Status DoHandleRequest | ( | WebServerRequest * | request | ) | [protected, virtual] |
Handles inbound request.
The base class method looks up a registered path handler that matches the url path prefix. It returns a 404 if one isnt found.
[in] | request | The request from the web server. |
virtual void DoShutdown | ( | ) | [protected, pure virtual] |
Implemented in MongooseWebServer.
virtual util::Status DoStartup | ( | ) | [protected, pure virtual] |
Implemented in MongooseWebServer.
PathHandler* FindPathHandler | ( | WebServerRequest * | request | ) | const |
Looks up added PathHandler that matches path.
Searches in the order they were added.
[in] | request | The request to lookup. |
string MakeEndpointUrl | ( | bool | use_localhost, |
const StringPiece & | path | ||
) | const |
Returns URL into this server for the given path.
[in] | use_localhost | If true use 'localhost' rather than the hostname. |
[in] | path | The path part of the url to build. |
int port | ( | ) | const [inline] |
Returns the port bound in the constructor.
void Shutdown | ( | ) |
Stops the server.
util::Status Startup | ( | ) |
Starts the server.
virtual string url_protocol | ( | ) | const [virtual] |
Returns the protocol part of the url used by this webserver (e.g.
'https')
Reimplemented in MongooseWebServer.