NuriaProject Framework  0.1
The NuriaProject Framework
Public Types | Public Member Functions | Friends | List of all members
Nuria::HttpServer Class Reference

Server for the HyperText Transfer Protocol. More...

#include <httpserver.hpp>

Inheritance diagram for Nuria::HttpServer:

Public Types

enum  ThreadingMode { NoThreading = 0, OneThreadPerCore = -1 }
 

Public Member Functions

 HttpServer (QObject *parent=0)
 
 ~HttpServer ()
 
void addBackend (HttpBackend *backend)
 
QVector< HttpBackend * > backends () const
 
QString fqdn () const
 
bool listen (const QHostAddress &interface=QHostAddress::Any, quint16 port=80)
 
bool listenSecure (const QSslCertificate &certificate, const QSslKey &privateKey, const QHostAddress &interface=QHostAddress::Any, quint16 port=443)
 
int maxThreads () const
 
HttpNoderoot () const
 
void setFqdn (const QString &fqdn)
 
void setMaxThreads (int amount)
 
void setRoot (HttpNode *node)
 
void stopListening (int port)
 

Friends

class HttpClient
 
class HttpNode
 
class HttpTransport
 

Detailed Description

Server for the HyperText Transfer Protocol.

This is a implementation of a server for HTTP. The server class itself is responsible for managing the "root node" (The equivalent to the document root in other HTTP servers).

Please see HttpNode and HttpClient

Note
For redirections to work properly, you should set the fully qualified domain name of the server using setFqdn().
Usage
After creating an instance of HttpServer, you can change the node hierarchy using root() or set your own using setRoot(). After that, you'll want to start listening. For TCP, there's listen() and for SSL there's listenSecure().
Note
A single HttpServer can listen on multiple back-ends (TCP, SSL, ...) at the same time.

Please see HttpNode for further information.

Multithreading

A HttpServer can either do all request execution in the thread it lifes in, which is the default setting, or use threading to offload requests. If threading is active (By using setMaxThreads), all request handling will be done in threads and none will be handled in the HttpServer thread.

Warning
When using multi-threading, be aware that your code is also thread-safe.

Tip: You can use DependencyManager to manage resources

Member Enumeration Documentation

Additional threading options for setMaxThreads().

Enumerator
NoThreading 

Uses no threads. All processing is done in the thread of the HttpServer instance.

OneThreadPerCore 

When passed to setMaxThreads(), one thread per CPU core will be created. maxThreads() will return the chosen value instead of OneThreadPerCore.

Constructor & Destructor Documentation

Nuria::HttpServer::HttpServer ( QObject *  parent = 0)

Constructor.

See also
listen listenSecure
Nuria::HttpServer::~HttpServer ( )

Destructor.

Member Function Documentation

void Nuria::HttpServer::addBackend ( HttpBackend backend)

Adds server to the list of back-ends. Use this when you write a server implementation. Ownership of server is transferred to the HttpServer.

QVector< HttpBackend * > Nuria::HttpServer::backends ( ) const

Returns a list of currently installed back-ends.

QString Nuria::HttpServer::fqdn ( ) const

Returns the fully-qualified domain name of this server.

See also
setFqdn
bool Nuria::HttpServer::listen ( const QHostAddress &  interface = QHostAddress::Any,
quint16  port = 80 
)

Adds a TCP server, listening on interface and port. Returns true on success.

bool Nuria::HttpServer::listenSecure ( const QSslCertificate &  certificate,
const QSslKey &  privateKey,
const QHostAddress &  interface = QHostAddress::Any,
quint16  port = 443 
)

Adds a SSL server, listening on interface and port. Returns true on success.

int Nuria::HttpServer::maxThreads ( ) const

Returns the amount of threads used to process requests. The default result is NoThreading.

HttpNode* Nuria::HttpServer::root ( ) const

Returns the root node.

void Nuria::HttpServer::setFqdn ( const QString &  fqdn)

Sets the fully-qualified domain name of this server.

void Nuria::HttpServer::setMaxThreads ( int  amount)

Sets the amount of threads to be used for processing requests. See ThreadingMode for other values that can be passed.

If the new value is less than the current one, requests running in the affected will be processed, after which they're destroyed.

void Nuria::HttpServer::setRoot ( HttpNode node)

Replaces the current root node with node. The old root node will be deleted. HttpServer will take ownership of node.

void Nuria::HttpServer::stopListening ( int  port)

Removes the back-end which is listening on port.


The documentation for this class was generated from the following file: