Google APIs Client Library for C++
MongooseWebServer Class Reference

Provides a web server for samples and testing. More...

#include "client/util/mongoose_webserver.h"

+ Inheritance diagram for MongooseWebServer:

List of all members.

Public Member Functions

 MongooseWebServer (int port)
 Constructs an http server on the given port.
virtual ~MongooseWebServer ()
 Standard destructor.
bool use_ssl () const
 Determines whether we are using SSL or not.
void set_mongoose_options (const map< string, string > &options)
 Override Mongoose options.
const map< string, string > & mongoose_options () const
 Returns Mongoose options that were overriden.
void clear_mongoose_options ()
 Clears Mongoose option overrides.
void set_mongoose_option (const StringPiece &name, const StringPiece &value)
 Explicitly configure an individual Mongoose server option.
const string mongoose_option (const string &name) const
 Returns value for individual option, or empty if not set.
void clear_mongoose_option (const StringPiece &name)
 Clears an overiden Mongoose options back to the default value.
virtual string url_protocol () const
 Returns actual protocol depending on whether SSL was enabled.

Static Public Attributes

static const StringPiece ACCESS_LOG_FILE
static const StringPiece DOCUMENT_ROOT
static const StringPiece ENABLE_KEEP_ALIVE
static const StringPiece ERROR_LOG_FILE
static const StringPiece LISTENING_PORTS
static const StringPiece NUM_THREADS
static const StringPiece REQUEST_TIMEOUT_MS
static const StringPiece SSL_CERTIFICATE

Protected Member Functions

virtual util::Status DoStartup ()
 Starts the server.
virtual void DoShutdown ()
 Stops the server.
int SendResponse (const StringPiece &content_type, int http_code, const StringPiece &body, struct mg_connection *connection)
 Sends the body response with the given http_code.

Detailed Description

Provides a web server for samples and testing.

This class and the use of Mongoose Web Server available from https://code.google.com/p/mongoose/

This class is currently only intended to support testing and tinkering. It is not robust for production use. The underlying library is probably sufficient, but this wrapper uses only minimal configuration and processing.


Constructor & Destructor Documentation

MongooseWebServer ( int  port) [explicit]

Constructs an http server on the given port.

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

Standard destructor.


Member Function Documentation

void clear_mongoose_option ( const StringPiece &  name) [inline]

Clears an overiden Mongoose options back to the default value.

void clear_mongoose_options ( ) [inline]

Clears Mongoose option overrides.

virtual void DoShutdown ( ) [protected, virtual]

Stops the server.

Returns:
ok or reason for error.

Implements AbstractWebServer.

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

Starts the server.

Returns:
ok or reason for error.

Implements AbstractWebServer.

const string mongoose_option ( const string &  name) const [inline]

Returns value for individual option, or empty if not set.

const map<string, string>& mongoose_options ( ) const [inline]

Returns Mongoose options that were overriden.

int SendResponse ( const StringPiece &  content_type,
int  http_code,
const StringPiece &  body,
struct mg_connection *  connection 
) [protected]

Sends the body response with the given http_code.

Parameters:
[in]content_typeThe MIME content_type for the response.
[in]http_codeThe HTTP status code to return.
[in]bodyThe HTTP body to return.
[in]connectionThe connection passed to the DoHandleUrl.
void set_mongoose_option ( const StringPiece &  name,
const StringPiece &  value 
) [inline]

Explicitly configure an individual Mongoose server option.

Parameters:
[in]nameSee the Mongoose Documentation for option names.
[in]valueSee the Mongoose Documentation for option values.
void set_mongoose_options ( const map< string, string > &  options) [inline]

Override Mongoose options.

This replaces the old options that were overriden.

Parameters:
[in]optionsThe options will be copied. They must be set before the server is started.
virtual string url_protocol ( ) const [virtual]

Returns actual protocol depending on whether SSL was enabled.

Reimplemented from AbstractWebServer.

bool use_ssl ( ) const [inline]

Determines whether we are using SSL or not.

Returns:
if we'll use SSL (https).

Member Data Documentation

const StringPiece ACCESS_LOG_FILE [static]
const StringPiece DOCUMENT_ROOT [static]
const StringPiece ENABLE_KEEP_ALIVE [static]
const StringPiece ERROR_LOG_FILE [static]
const StringPiece LISTENING_PORTS [static]
const StringPiece NUM_THREADS [static]
const StringPiece REQUEST_TIMEOUT_MS [static]
const StringPiece SSL_CERTIFICATE [static]

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