Documents > BPS V2 C++ API

BPS MDE request. More...

#include <bpsmderequest.h>

List of all members.

Public Types

enum  Method {
  GET,
  POST,
  HEAD,
  PUT,
  DELETE,
  TRACE,
  OPTIONS,
  CONNECT
}
 Request methods. More...
enum  MimeType {
  M_html,
  M_css,
  M_js,
  M_htc,
  M_ico,
  M_png,
  M_gif,
  M_jpg
}
 MIME types used by BPS MDE server. More...
enum  Status {
  S_OK = 200,
  S_SeeOther = 303,
  S_Forbidden = 403,
  S_NotFound = 404,
  S_NotAllowed = 405,
  S_ServerError = 500
}
 HTML status codes. More...

Public Member Functions

 BpsMdeRequest (QTcpSocket *aSocket, QObject *aParent=0)
 Constructor for the BpsMdeRequest objects.
QByteArray data () const
QString endl () const
QString host () const
QTextStream & html ()
QString location () const
Method method () const
QString methodAsText () const
MimeType mimeType () const
bool mustClose () const
QVariantMap params () const
 For GET/POST parameter names ending with [], the values are stored as QStringList and the [] is removed from the name.
QString path () const
QString protocol () const
void redirect (const QString &aPath=QString())
 A convenience function to make redirections on the current server.
void sendReply ()
 Send the reply back to the client after setting the necessary status, text etc.
qlonglong sessionId () const
void setData (const QByteArray &aData)
 Put file contents to reply with in this.
void setLocation (const QString &aLocation)
 Set a redirection URL.
void setMaxAge (quint32 aSeconds)
 Set the content cache seconds.
void setMimeType (MimeType aMimeType)
 Set the MIME type for the reply.
void setMustClose ()
 Force connection close after reply.
void setSessionId (qlonglong aSessionId)
 Set a new session ID.
void setStatus (Status aStatus)
 Set the status for the reply.
QTcpSocket * socket () const
Status status () const

Static Public Member Functions

static MimeType getMimeType (const QString &aPath)
 Get the MIME type from a file name.
static QString httpDate (const QDateTime &aUtcDateTime)
 Format a UTC timestamp as HTTP date.

Detailed Description

BPS MDE request.

This is basically a data container where the information of the parsed client request are first filled in by the MDE server. The request is then passed to the appropriate applications request handler to get the reply information added. Finally the MDE server takes the reply information and sends the reply back to the client.


Member Enumeration Documentation

Request methods.

Usually applications only need to handle GET and POST. The other requests are handled by the MDE server.

Enumerator:
GET 

Request a resource from server.

POST 

Send data to server.

HEAD 

Like GET, but no body data sent.

PUT 

Upload a resource to server.

DELETE 

Delete a resource from server.

TRACE 

Loopback the request.

OPTIONS 

Query options supported by server.

CONNECT 

Server with proxy capability redirection.

MIME types used by BPS MDE server.

Enumerator:
M_html 

Hypertext markup.

M_css 

Cascaded style sheet.

M_js 

Javascript.

M_htc 

HTML component.

M_ico 

Microsoft format icon.

M_png 

Portable network graphics.

M_gif 

Graphics interchange format.

M_jpg 

JPEG graphics.

HTML status codes.

Enumerator:
S_OK 

Request succeeded.

S_SeeOther 

Request normal result is a redirection.

S_Forbidden 

Not authorized access.

S_NotFound 

Requested resource not found.

S_NotAllowed 

Client error, not allowed.

S_ServerError 

General server error.


Constructor & Destructor Documentation

BpsMdeRequest::BpsMdeRequest ( QTcpSocket *  aSocket,
QObject *  aParent = 0 
)

Constructor for the BpsMdeRequest objects.

Parameters:
aSocketSocket having request lines ready to get read.
aParentPointer to an optional parent object.

Member Function Documentation

QByteArray BpsMdeRequest::data ( ) const
Returns:
The data to send back to the client in the reply. Filled directly by the request handler for images and files, or indirectly the html stream for dynamic html content.
QString BpsMdeRequest::endl ( ) const
Returns:
Endline character(s) depending on the operating system (cr lf, or only lf). Use this to optionally break the html stream in lines for better human readability.
static MimeType BpsMdeRequest::getMimeType ( const QString &  aPath) [static]

Get the MIME type from a file name.

Parameters:
[in]aPathThe file name or path.
Returns:
The MIME type.
QString BpsMdeRequest::host ( ) const
Returns:
The host URL found in the clients request.
QTextStream& BpsMdeRequest::html ( )
Returns:
A text stream open already for convenience, operating on the data byte array. The stream has AutoDetectUnicode set to true.
static QString BpsMdeRequest::httpDate ( const QDateTime &  aUtcDateTime) [static]

Format a UTC timestamp as HTTP date.

Parameters:
[in]aUtcDateTimeThe date/time to format.
Returns:
The formatted date
QString BpsMdeRequest::location ( ) const
Returns:
Redirect location.
Method BpsMdeRequest::method ( ) const
Returns:
The method of the request.
QString BpsMdeRequest::methodAsText ( ) const
Returns:
The method as text.
MimeType BpsMdeRequest::mimeType ( ) const
Returns:
Mime type of the reply. Initialized to M_html, change by request handler as needed.
bool BpsMdeRequest::mustClose ( ) const
Returns:
True if the MDE server must close the connection after reply.
QVariantMap BpsMdeRequest::params ( ) const

For GET/POST parameter names ending with [], the values are stored as QStringList and the [] is removed from the name.

For other names the values are stored as QString; multiple values with same name are joined by comma in case.

Returns:
The GET/POST parameters received in the clients request.
QString BpsMdeRequest::path ( ) const
Returns:
The requested path (URL), without the GET parameters.
QString BpsMdeRequest::protocol ( ) const
Returns:
The protocol used in the clients request, either HTTP/1.0 or HTTP/1.1.
void BpsMdeRequest::redirect ( const QString &  aPath = QString())

A convenience function to make redirections on the current server.

Status is set to S_SeeOther, the URL is created in the location field using the host name from the clients request, and HTML with a redirection link is added. sendReply() is called at the end, so there is no need to it after this function.

Parameters:
[in]aPathThe path to redirect to.
qlonglong BpsMdeRequest::sessionId ( ) const
Returns:
The current session ID. Initially this is highest session number found in the cookies of the request header, or -1 if none found.
void BpsMdeRequest::setData ( const QByteArray &  aData)

Put file contents to reply with in this.

Use the html stream instead to fill with dynamic html code.

Parameters:
[in]aDataThe data posted back to the client.
void BpsMdeRequest::setLocation ( const QString &  aLocation)

Set a redirection URL.

Also set status to S_SeeOther when doing this.

Parameters:
[in]aLocationThe redirection URL.
void BpsMdeRequest::setMaxAge ( quint32  aSeconds)

Set the content cache seconds.

The default is 0, which means no caching.

Parameters:
[in]aSecondsSeconds to allow caching.
void BpsMdeRequest::setMimeType ( MimeType  aMimeType)

Set the MIME type for the reply.

Parameters:
[in]aMimeTypeThe new MIME type.
void BpsMdeRequest::setSessionId ( qlonglong  aSessionId)

Set a new session ID.

If the new session ID differs from the one received in the clients request, it will create a new session cookie upon reply.

Parameters:
[in]aSessionIdThe new session ID.
void BpsMdeRequest::setStatus ( Status  aStatus)

Set the status for the reply.

Parameters:
[in]aStatusThe new status to set.
QTcpSocket* BpsMdeRequest::socket ( ) const
Returns:
The TCP/IP socket.
Status BpsMdeRequest::status ( ) const
Returns:
The status for the reply. Initialized to S_OK, change by request handler as needed.

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