NuriaProject Framework
0.1
The NuriaProject Framework
|
FastCGI integration for HttpServer. More...
#include <fastcgibackend.hpp>
Signals | |
void | connectionAdded () |
void | connectionClosed () |
Public Member Functions | |
FastCgiBackend (HttpServer *server) | |
~FastCgiBackend () override | |
int | currentConnectionCount () const |
QMap< QByteArray, QByteArray > | customConfiguration () const |
bool | isListening () const |
bool | isSecure () const |
bool | listen () |
bool | listen (int port, const QHostAddress &iface=QHostAddress::Any) |
bool | listenLocal (const QString &name, QLocalServer::SocketOptions options=QLocalServer::NoOptions) |
bool | listenLocal (qintptr handle) |
int | maxConcurrentConnections () const |
int | maxConcurrentRequests () const |
int | port () const |
void | setCustomConfiguration (const QByteArray &name, const QByteArray &value) |
void | setMaxConcurrentConnections (int count) |
void | setMaxConcurrentRequests (int count) const |
void | stop () |
![]() | |
HttpBackend (HttpServer *server) | |
~HttpBackend () | |
HttpServer * | httpServer () const |
Protected Member Functions | |
void | serverThreadCreated (QThread *thread) override |
Friends | |
class | Internal::FastCgiThreadObject |
FastCGI integration for HttpServer.
This class provides a FastCGI backend for HttpServer. Using this you can write FastCGI servers easily.
This implementation supports both, opening a TCP socket which the front-end HTTP server pushes requests to or inheriting the socket opened by the front-end server from the FCGI_LISTENSOCK_FILENO
environment variable.
FastCGI front-end servers pass "parameters" to FastCGI applications to tell them about incoming connections. These are comparable to environment variables or HTTP headers.
The following parameters are needed by FastCgiBackend:
REQUEST_METHOD
(HTTP verb)REQUEST_URI
(Path)REMOTE_ADDR
(Peer address)REMOTE_PORT
(Peer port)SERVER_ADDR
(Server address)SERVER_PORT
(Server port)SERVER_PROTOCOL
("HTTP/1.x")Parameters whose name begin with "HTTP_" are stripped of that prefix. All FastCGI parameters are forwarded to the HttpClient and can be accessed by HttpClient::requestHeader(), with names are converted from "THIS_FORMAT" to "This-Format". Example:
You should think about where to put your logs. Some front-end servers support receiving log messages through the standard output or error streams. Whatever you choose, if you need to change the default logging target, see Debug::setDestination().
It should be pointed out that all tested front-end HTTP servers, namely lighttpd and nginx, work equally well with this implementation in normal circumstances. Though it should be noted that benchmarking showed that nginx is inferior to lighttpd one. With about 1k concurrent requests done by the benchmarking utility, nginx suffered from having issues serving the last ca. 10% of all requests. Lighttpd does not have this restriction.
These restriction do not apply when configuring both servers to act as a HTTP proxy and relying on the NuriaFrameworks HTTP implementation.
|
explicit |
Constructor.
|
override |
Destructor.
|
signal |
The FastCGI front-end server has opened a new connection to the back-end.
|
signal |
The FastCGI front-end server has closed a connection.
Qt::DirectConnection
. int Nuria::FastCgiBackend::currentConnectionCount | ( | ) | const |
Returns the count of connections currently opened by the FastCGI front-end server.
QMap< QByteArray, QByteArray > Nuria::FastCgiBackend::customConfiguration | ( | ) | const |
Returns teh custom configuration map.
|
virtual |
Returns true
if the server is currently listening for connections.
Implements Nuria::HttpBackend.
|
virtual |
Returns true
if this back-end uses secure connections. The default implementation returns false
.
Reimplemented from Nuria::HttpBackend.
bool Nuria::FastCgiBackend::listen | ( | ) |
Start listening on the socket forwarded to this process. This is mainly there for front-end servers
bool Nuria::FastCgiBackend::listen | ( | int | port, |
const QHostAddress & | iface = QHostAddress::Any |
||
) |
Listen for TCP connections on port and iface.
bool Nuria::FastCgiBackend::listenLocal | ( | const QString & | name, |
QLocalServer::SocketOptions | options = QLocalServer::NoOptions |
||
) |
Listens on name using a QLocalServer.
bool Nuria::FastCgiBackend::listenLocal | ( | qintptr | handle | ) |
Listens on handle using a QLocalServer.
int Nuria::FastCgiBackend::maxConcurrentConnections | ( | ) | const |
Returns the max amount of concurrent connections. Defaults to the count of CPU cores of the host machine.
int Nuria::FastCgiBackend::maxConcurrentRequests | ( | ) | const |
Returns the max amount of concurrent requests. Defaults to: (count of CPU cores) * 10
|
virtual |
Returns the port this server is listening on, or -1
if it's not listening.
Implements Nuria::HttpBackend.
|
overrideprotectedvirtual |
Called by the HttpServer when a new server thread has been created. This lets back-ends register their own thread-specific bookkeeping routines.
This function will also be called by the HttpServer if no multi-threading is used. In this case, the function will be called once with thread being the one the server is associated with.
To run some kind of initialization after the thread has been started, use one of:
The default implementation does nothing.
Reimplemented from Nuria::HttpBackend.
void Nuria::FastCgiBackend::setCustomConfiguration | ( | const QByteArray & | name, |
const QByteArray & | value | ||
) |
Sets a custom configuration field for FastCGI front-end servers. This field will be sent to the FCGI server after receiving a FCGI_GET_VALUES
request.
If there's already a configuration for name, it will be overriden.
void Nuria::FastCgiBackend::setMaxConcurrentConnections | ( | int | count | ) |
Sets the max amount of concurrent connections.
void Nuria::FastCgiBackend::setMaxConcurrentRequests | ( | int | count | ) | const |
Sets the max amount of concurrent requests.
void Nuria::FastCgiBackend::stop | ( | ) |
Stops listening immediately.