Wexus2 0.20
|
#include <HTTP.h>
Classes | |
struct | ServerCookie |
Public Types | |
typedef QMap< QString, ServerCookie > | ServerCookies |
Public Member Functions | |
HTTPReply (QTextStream &outstream) | |
~HTTPReply () | |
void | setStatus (int status) |
int | status (void) const |
bool | hasReply (void) const |
void | setContentType (const QString &type) |
const QString & | contentType (void) const |
QTextStream & | output (void) |
const ServerCookies & | cookies (void) const |
ServerCookies & | cookies (void) |
void | redirectTo (const QString &rawurl) |
Static Public Member Functions | |
static const char * | statusToString (int status) |
Protected Attributes | |
QTextStream & | dm_outs |
int | dm_status |
bool | dm_calledcommit |
QString | dm_contenttype |
ServerCookies | dm_servercookies |
A HTTP reply that is sent back to the client as a result of an HTTP request.
The status may be set via the constructor, and or changed via setStatus. In eithercase, a reply with a 0 status is invalid and cannot be commited (used).
wexus::HTTPReply::HTTPReply | ( | QTextStream & | outstream | ) |
Constructs an http reply, using the given stream and with the given status code.
If your handler wants to respond to a request, must call output() (and produce some output), setStatus() or both.
wexus::HTTPReply::~HTTPReply | ( | ) |
This calls the commitHeader method if status is >0 AND commitHeader() has not yet been called.
const QString& wexus::HTTPReply::contentType | ( | void | ) | const [inline] |
Returns the currently set content type. The default content type is text/html.
const ServerCookies& wexus::HTTPReply::cookies | ( | void | ) | const [inline] |
Returns the cookies sent by the client.
ServerCookies& wexus::HTTPReply::cookies | ( | void | ) | [inline] |
Returns the cookies sent by the client. non-const version. Callers can fiddle with the cookie map for convience.
bool wexus::HTTPReply::hasReply | ( | void | ) | const [inline] |
True is a reply has been status (status is non-zero)
QTextStream& wexus::HTTPReply::output | ( | void | ) |
Returns a stream that you can use to write the reply body. This called commitHeader() before hand, if it hasn't been called already.
You may want to include wx/streamop.h
void wexus::HTTPReply::redirectTo | ( | const QString & | rawurl | ) |
Sets a cookie that will be sent to the client. There can be many of these.
This cannot be called after commitHeader() has been called.
name | the name of the cookie |
value | the value of the cookie |
expires | the expiry of the cookie, in "Wdy, DD-Mon-YYYY HH:MM:SS GMT" format. If empty, a "session cookie" will be created. Negative time values aparently delete cookies. |
domain | the domain name of servers that this cookie will be sent to. May be empty ("same as caller"), and may also be a suffix (".example.com") I guess to specify a collection of servers |
path | The path prefix this cookie is good for. examples: "/" and "/accounts" |
void wexus::HTTPReply::setContentType | ( | const QString & | type | ) |
Sets the content type. The default content type is text/html.
void wexus::HTTPReply::setStatus | ( | int | status | ) |
Sets the current status code that will be returned. The default status is 0, unless output() is used, in which case it is 200.
int wexus::HTTPReply::status | ( | void | ) | const [inline] |
Gets the current return status code. If its 0, it means unset (reply not set).
static const char* wexus::HTTPReply::statusToString | ( | int | status | ) | [static] |
Converts a status code to a description, null if this is an unkown status code. Uses const char * to minimuze copies.