tufao  0.8.1
An asynchronous web framework for C++ built on top of Qt
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Tufao::HttpServerRequest Class Reference

The Tufao::HttpServer represents a HTTP request received by Tufao::HttpServer. More...

+ Inheritance diagram for Tufao::HttpServerRequest:
+ Collaboration diagram for Tufao::HttpServerRequest:

Public Types

enum  HttpVersion { HTTP_1_0, HTTP_1_1 }
 

Signals

void ready (Tufao::HttpServerResponse::Options)
 
void ready ()
 This signal is emitted when most of the data about the request is available. More...
 
void data (QByteArray data)
 This signal is emitted each time a piece of the message body is received. More...
 
void end ()
 This signal is emitted exactly once for each request. More...
 
void close ()
 This signal is emitted when the underlaying connection is closed (also caused by invalid requests). More...
 
void upgrade (QByteArray head)
 This signal is emitted when a http upgrade is requested. More...
 

Public Member Functions

 HttpServerRequest (QAbstractSocket *socket, QObject *parent=0)
 Constructs a Tufao::HttpServerRequest object. More...
 
 ~HttpServerRequest ()
 Destroys the object.
 
QByteArray method () const
 The request method. More...
 
void setUrl (const QByteArray &url)
 Sets the request URL. More...
 
QByteArray url () const
 The request URL. More...
 
Headers headers () const
 The HTTP headers sent by the client. More...
 
Headersheaders ()
 The HTTP headers sent by the client. More...
 
Headers trailers () const
 The HTTP trailers (if present). More...
 
HttpVersion httpVersion () const
 Returns the HTTP protocol version used in the request.
 
QAbstractSocket * socket () const
 The QAbstractSocket object associated with the connection. More...
 
void setTimeout (int msecs=0)
 Sets the timeout of new connections to msecs miliseconds. More...
 
int timeout () const
 Returns the current set timeout.
 
Tufao::HttpServerResponse::Options responseOptions () const
 Returns the options obje that should be passed to the Tufao::HttpServerResponse constructor. More...
 

Friends

struct Tufao::HttpServerRequest::Priv
 

Detailed Description

The Tufao::HttpServer represents a HTTP request received by Tufao::HttpServer.

Note
You can use it to create your own HTTP servers too, just handle the connections steps and pass the connection objects to Tufao::HttpServerRequest constructor. This may be useful if you want to create a threaded web server or use non conventional streams instead tcp sockets.
See Also
Tufao::HttpServer

Constructor & Destructor Documentation

Tufao::HttpServerRequest::HttpServerRequest ( QAbstractSocket *  socket,
QObject *  parent = 0 
)
explicit

Constructs a Tufao::HttpServerRequest object.

parent is passed to the QObject constructor.

Parameters
socketThe connection used by Tufao::HttpServerRequest to receive HTTP messages. If you pass NULL, the object will be useless.

Member Function Documentation

void Tufao::HttpServerRequest::close ( )
signal

This signal is emitted when the underlaying connection is closed (also caused by invalid requests).

Just like Tufao::HttpServerRequest::end, this signal is emitted only once per request, and no more data signals will fire afterwards.

void Tufao::HttpServerRequest::data ( QByteArray  data)
signal

This signal is emitted each time a piece of the message body is received.

Note
This signal is unsafe (read this: Safe signals)!
void Tufao::HttpServerRequest::end ( )
signal

This signal is emitted exactly once for each request.

After that, no more data signals will be emitted for this session. A new session (if any) will be only initiated after you respond the request.

Headers Tufao::HttpServerRequest::headers ( ) const

The HTTP headers sent by the client.

These headers are fully populated when the signal Tufao::HttpServerRequest::ready signal is emitted.

See Also
Tufao::HttpServerRequest::trailers()
Headers& Tufao::HttpServerRequest::headers ( )

The HTTP headers sent by the client.

These headers are fully populated when the signal Tufao::HttpServerRequest::ready signal is emitted.

See Also
Tufao::HttpServerRequest::trailers()
Since
0.3
QByteArray Tufao::HttpServerRequest::method ( ) const

The request method.

It can assume the following values:

  • "HEAD"
  • "GET"
  • "POST"
  • "PUT"
  • "DELETE"
  • "TRACE"
  • "OPTIONS"
  • "CONNECT"
  • "PATCH"
  • "COPY"
  • "LOCK"
  • "MKCOl"
  • "MOVE"
  • "PROPFIND"
  • "PROPPATCH"
  • "SEARCH"
  • "UNLOCK"
  • "REPORT"
  • "MKACTIVITY"
  • "CHECKOUT"
  • "MERGE"
  • "M-SEARCH"
  • "NOTIFY"
  • "SUBSCRIBE"
  • "UNSUBSCRIBE"
  • "PURGE"
void Tufao::HttpServerRequest::ready ( Tufao::HttpServerResponse::Options  )
signal
Deprecated:

It'll be removed in 1.0 version.

Use ready().

void Tufao::HttpServerRequest::ready ( )
signal

This signal is emitted when most of the data about the request is available.

After this signal is emitted, you can safely interpret the request and the only missing parts may be (if any) the message body and the trailers.

Note
This signal is unsafe (read this: Safe signals)!
See Also
Tufao::HttpServerRequest::responseOptions Tufao::HttpServerRequest::data Tufao::HttpServerRequest::end
Since
0.2
Tufao::HttpServerResponse::Options Tufao::HttpServerRequest::responseOptions ( ) const

Returns the options obje that should be passed to the Tufao::HttpServerResponse constructor.

Since
0.2
void Tufao::HttpServerRequest::setTimeout ( int  msecs = 0)

Sets the timeout of new connections to msecs miliseconds.

The connection will be closed when no bytes are received during msecs miliseconds.

If you set the timeout to 0, then timeout feature will be disabled.

By default, there is no timeout.

You can call this function at any time.

void Tufao::HttpServerRequest::setUrl ( const QByteArray &  url)

Sets the request URL.

See Also
UrlRewriterHandler
Since
0.6
QAbstractSocket* Tufao::HttpServerRequest::socket ( ) const

The QAbstractSocket object associated with the connection.

This will be a QTcpSocket object if created by Tufao::HttpServer and a QSslSocket if created by Tufao::HttpsServer.

Headers Tufao::HttpServerRequest::trailers ( ) const

The HTTP trailers (if present).

Only populated after the Tufao::HttpServerRequest::end signal.

void Tufao::HttpServerRequest::upgrade ( QByteArray  head)
signal

This signal is emitted when a http upgrade is requested.

Note
If this signal is emitted, then the signals HttpServerRequest::ready, HttpServerRequest::end and HttpServerRequest::close won't be emitted.
Parameters
headThe initial bytes from the new connection protocol.
QByteArray Tufao::HttpServerRequest::url ( ) const

The request URL.

This contains only the URL that is present in the actual HTTP request. If the request is:

GET /login?username=tux HTTP/1.1\r\n
Accept: text/plain\r\n
\r\n

Then Tufao::HttpServerRequest::url() will be "/login?username=tux"

See Also
Tufao::Url

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