Google APIs Client Library for C++
AbstractWebServer Class Reference

A minimal abstract interface for embedded webservers. More...

#include "client/util/abstract_webserver.h"

+ Inheritance diagram for AbstractWebServer:

List of all members.

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.
PathHandlerFindPathHandler (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.

Detailed Description

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.


Member Typedef Documentation

typedef ResultCallback1< util::Status, WebServerRequest*> PathHandler

Used to register a callback on particular URIs or trees.

Parameters:
[in]requestfor the request being processed.
Returns:
ok or reason for failure.

Constructor & Destructor Documentation

AbstractWebServer ( int  port) [explicit]

Constructs an http server on the given port.

Parameters:
[in]portShould be non-0.
virtual ~AbstractWebServer ( ) [virtual]

Standard destructor.


Member Function Documentation

void AddPathHandler ( const string &  path,
PathHandler handler 
)

Inject handler for path.

Parameters:
[in]pathThe path to intercept with this handler.
[in]handlerA 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.

Parameters:
[in]requestThe request from the web server.
virtual void DoShutdown ( ) [protected, pure virtual]

Implemented in MongooseWebServer.

virtual util::Status DoStartup ( ) [protected, pure virtual]

Implemented in MongooseWebServer.

Looks up added PathHandler that matches path.

Searches in the order they were added.

Parameters:
[in]requestThe request to lookup.
Returns:
path handler or NULL if one could not be found.
string MakeEndpointUrl ( bool  use_localhost,
const StringPiece &  path 
) const

Returns URL into this server for the given path.

Parameters:
[in]use_localhostIf true use 'localhost' rather than the hostname.
[in]pathThe path part of the url to build.
int port ( ) const [inline]

Returns the port bound in the constructor.

void Shutdown ( )

Stops the server.

Returns:
ok or reason for error.

Starts the server.

Returns:
ok or reason for error.
virtual string url_protocol ( ) const [virtual]

Returns the protocol part of the url used by this webserver (e.g.

'https')

Reimplemented in MongooseWebServer.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines