tufao
0.8.1
An asynchronous web framework for C++ built on top of Qt
|
The Tufao::HttpServerResponse is used to respond to a Tufao::HttpServerRequest. More...
Public Types | |
enum | StatusCode { CONTINUE = 100, SWITCHING_PROTOCOLS = 101, PROCESSING = 102, CHECKPOINT = 103, OK = 200, CREATED = 201, ACCEPTED = 202, NON_AUTHORITATIVE_INFORMATION = 203, NO_CONTENT = 204, RESET_CONTENT = 205, PARTIAL_CONTENT = 206, MULTI_STATUS = 207, ALREADY_REPORTED = 208, IM_USED = 226, MULTIPLE_CHOICES = 300, MOVED_PERMANENTLY = 301, FOUND = 302, SEE_OTHER = 303, NOT_MODIFIED = 304, USE_PROXY = 305, SWITCH_PROXY = 306, TEMPORARY_REDIRECT = 307, RESUME_INCOMPLETE = 308, BAD_REQUEST = 400, UNAUTHORIZED = 401, PAYMENT_REQUIRED = 402, FORBIDDEN = 403, NOT_FOUND = 404, METHOD_NOT_ALLOWED = 405, NOT_ACCEPTABLE = 406, PROXY_AUTHENTICATION_REQUIRED = 407, REQUEST_TIMEOUT = 408, CONFLICT = 409, GONE = 410, LENGTH_REQUIRED = 411, PRECONDITION_FAILED = 412, REQUEST_ENTITY_TOO_LARGE = 413, REQUEST_URI_TOO_LONG = 414, UNSUPPORTED_MEDIA_TYPE = 415, REQUESTED_RANGE_NOT_SATISFIABLE = 416, EXPECTATION_FAILED = 417, I_AM_A_TEAPOT = 418, UNPROCESSABLE_ENTITY = 422, LOCKED = 423, FAILED_DEPENDENCY = 424, UNORDERED_COLLECTION = 425, UPGRADE_REQUIRED = 426, PRECONDITION_REQUIRED = 428, TOO_MANY_REQUESTS = 429, REQUEST_HEADER_FIELDS_TOO_LARGE = 431, NO_RESPONSE = 444, RETRY_WITH = 449, CLIENT_CLOSED_REQUEST = 499, INTERNAL_SERVER_ERROR = 500, NOT_IMPLEMENTED = 501, BAD_GATEWAY = 502, SERVICE_UNAVAILABLE = 503, GATEWAY_TIMEOUT = 504, HTTP_VERSION_NOT_SUPPORTED = 505, VARIANT_ALSO_NEGOTIATES = 506, INSUFFICIENT_STORAGE = 507, LOOP_DETECTED = 508, BANDWIDTH_LIMIT_EXCEEDED = 509, NOT_EXTENDED = 510 } |
The values in this enum represents a HTTP status code. More... | |
enum | Option { HTTP_1_0 = 1, HTTP_1_1 = 1 << 1, KEEP_ALIVE = 1 << 2 } |
This enum represents some aspects of a HTTP response. More... | |
Public Slots | |
bool | writeContinue () |
Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent. More... | |
bool | writeHead (int statusCode, const QByteArray &reasonPhrase, const Headers &headers) |
Sends a response header to the request. More... | |
bool | writeHead (int statusCode, const QByteArray &reasonPhrase) |
This is an overloaded function. More... | |
bool | writeHead (int statusCode, const Headers &headers) |
This is an overloaded function. More... | |
bool | writeHead (int statusCode) |
This is an overloaded function. More... | |
bool | write (const QByteArray &chunk) |
This sends a chunk of the response body. More... | |
bool | addTrailers (const Headers &headers) |
This method adds HTTP trailing headers (a header but at the end of the message) to the response. More... | |
bool | addTrailer (const QByteArray &headerName, const QByteArray &headerValue) |
This method adds one HTTP trailing header (a header but at the end of the message) to the response. More... | |
bool | end (const QByteArray &chunk=QByteArray()) |
This method signals to the server that all of the response headers and body has been sent; that server should consider this message complete. More... | |
Signals | |
void | finished () |
This signal is emitted when all bytes from the HTTP response message are written in the device/socket (not confuse with delivered). More... | |
Public Member Functions | |
HttpServerResponse (QIODevice *device, Options options, QObject *parent=0) | |
Constructs a Tufao::HttpServerResponse object. More... | |
~HttpServerResponse () | |
Destroys the object. | |
Options | options () const |
Returns the options passed to the object constructor. | |
const Headers & | headers () const |
Returns a const reference to the headers which will be sent when the first piece of body is written. More... | |
Headers & | headers () |
Returns a reference to the headers which will be sent when the first piece of body is written. More... | |
HttpServerResponse & | operator<< (const QByteArray &chunk) |
This overload allows you to use a HttpServerResponse object as a stream. More... | |
bool | flush () |
This method calls QAbstractSocket::flush for the object passed in the constructor. More... | |
The Tufao::HttpServerResponse is used to respond to a Tufao::HttpServerRequest.
A response is built of well defined parts and must be sent ordered. The order to send these parts are:
The values in this enum represents a HTTP status code.
These are sent in the first line of a HTTP response message. You should consult external doc (rfc 2616) to know when to use each value. The HTTP status code most used is OK.
You can use the values in this enum in Tufao::HttpServerResponse::writeHead(int).
|
explicit |
Constructs a Tufao::HttpServerResponse object.
parent
is passed to the QObject constructor.
options | It controls some aspects of the response. |
device | The socket used by Tufao::HttpServerResponse to write a HTTP response message. If you pass NULL, the object will do nothing. |
|
slot |
This method adds one HTTP trailing header (a header but at the end of the message) to the response.
|
slot |
This method adds HTTP trailing headers (a header but at the end of the message) to the response.
|
slot |
This method signals to the server that all of the response headers and body has been sent; that server should consider this message complete.
It MUST be called on each response exactly one time.
chunk | If specified, it is equivalent to calling Tufao::HttpServerResponse::write followed by Tufao::HttpServerResponse::end |
|
signal |
This signal is emitted when all bytes from the HTTP response message are written in the device/socket (not confuse with delivered).
Call Tufao::HttpServerResponse::end will cause this signal to be emitted.
bool Tufao::HttpServerResponse::flush | ( | ) |
This method calls QAbstractSocket::flush for the object passed in the constructor.
It'll do nothing and return false if the object passed in the constructor isn't an actual QAbstractSocket instance.
const Headers& Tufao::HttpServerResponse::headers | ( | ) | const |
Returns a const reference to the headers which will be sent when the first piece of body is written.
Headers& Tufao::HttpServerResponse::headers | ( | ) |
Returns a reference to the headers which will be sent when the first piece of body is written.
Use this reference to send custom headers.
|
inline |
This overload allows you to use a HttpServerResponse object as a stream.
|
slot |
This sends a chunk of the response body.
This method may be called multiple times to provide successive parts of the body.
The first time Tufao::HttpServerResponse::write is called, it will send the buffered headers and the first body chunk to the client. The second time Tufao::HttpServerResponse::write is called, it assumes you're going to streaming data, and sends that separately. That is, the response is buffered up to the first chunk of body.
If you call this function with a empty byte array, it will do nothing.
|
slot |
Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent.
You should write a HTTP/1.1 100 Continue response to requests that include 100-continue in the header Expect if you are willing to accept the request body based on the headers sent.
If you don't want to accept the request body, you should respond it with an Tufao::HttpServerResponse::EXPECTATION_FAILED response status.
The purpose of the 100 Continue status is to decrease the network traffic by avoiding the transfer of data that the server would reject anyway.
|
slot |
Sends a response header to the request.
Call this function after the first chunk of entity body data was already sent (calling Tufao::HttpServerResponse::write ) will have no effect.
statusCode | The status code is a 3-digit HTTP status code. |
reasonPhrase | A human-readable reasonPhrase. |
headers | The response headers. |
|
slot |
This is an overloaded function.
|
slot |
This is an overloaded function.
|
slot |
This is an overloaded function.