tufao  1.3.0
An asynchronous web framework for C++ built on top of Qt
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:

Signals

void ready ()
 This signal is emitted when most of the data about the request is available. More...
 
void 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 ()
 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 QUrl &url)
 Sets the request URL. More...
 
QUrl 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.
 
QByteArray readBody ()
 Read the request's body. More...
 
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...
 
QVariant customData () const
 Returns the user data as set in setCustomData. More...
 
void setCustomData (const QVariant &data)
 Sets the custom data to data. 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.
Since
1.0

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.

QVariant Tufao::HttpServerRequest::customData ( ) const

Returns the user data as set in setCustomData.

Note
This data will be erased upon a new request.
See also
setCustomData
Since
1.0
void Tufao::HttpServerRequest::data ( )
signal

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

Use readBody() to consume the data.

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

This signal is emitted exactly once for each request.

Use readBody() to access the request's body and trailers() to access the headers sent after the body.

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"
QByteArray Tufao::HttpServerRequest::readBody ( )

Read the request's body.

Returns
This request's object will buffer every piece of body received. After call this function, the buffered content is returned and the buffer is cleared.
Note
If you only call this function after end() signal, the returned object will be the entire body of the request. Call this function when the data() signal is emitted and save the body to disk if you expect to receive requests with bodies larger than available RAM.
See also
data() end()
Since
1.0
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)!
Warning
Right before emit this signal, HttpServerRequest object will disconnect any slot connected to the signals listed below. This behaviour was chosen to allow you to think about the single HTTP session without worry about the Tufão behaviour of reuse the same objects to the same connections.
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::setCustomData ( const QVariant &  data)

Sets the custom data to data.

The custom data is a convenience method to allow users of HttpServerRequest to store some data in some requests. It's used in Tufao::HttpServerRequestRouter to pass the list of captured texts in the url to the subsequent handlers.

Note
This data will be erased upon a new request.
Since
1.0
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 QUrl &  url)

Sets the request URL.

See also
UrlRewriterHandler
Since
1.0
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.

Since
1.0
Headers Tufao::HttpServerRequest::trailers ( ) const

The HTTP trailers (if present).

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

Trailers are headers sent after the body. Some headers can't be computed before the full body is generated. The solution to decrease the network latency is send the body before the associated metadata using the trailers technique.

void Tufao::HttpServerRequest::upgrade ( )
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.

The body is set to the initial bytes from the new connection session (under the new protocol).

Since
1.0
QUrl 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 constructed with "/login?username=tux".

Since
1.0

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