Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

qhttpservletresponse.h

00001 // -*- c++ -*-
00002 
00003 #ifndef QHTTPSERVLETRESPONSE_H
00004 #define QHTTPSERVLETRESPONSE_H
00005 
00006 #include <qmap.h>
00007 #include <qstring.h>
00008 
00009 #include <qhttpservletrequest.h>
00010 #include <qservletresponse.h>
00011 
00012 class QDateTime;
00013 
00014 class QHttpServletRequest;
00015 class QCookie;
00016 
00020 class QHttpServletResponse : public QServletResponse
00021 {
00022 public:
00024    enum ResponseStatus {
00025       StatusNull = 0,
00026       
00027       StatusContinue = 100,
00028       StatusSwitchingProtocols = 101,
00029       
00030       StatusOk = 200,
00031       StatusCreated = 201,
00032       StatusAccepted = 202,
00033       StatusNonAuthoritativeInformation = 203,
00034       StatusNoContent = 204,
00035       StatusResetContent = 205,
00036       StatusPartialContent = 206,
00037       
00038       StatusMultipleChoices = 300,
00039       StatusMovedPermanently = 301,
00040       StatusMovedTemporarily = 302,
00041       StatusSeeOther = 303,
00042       StatusNotModified = 304,
00043       StatusUseProxy = 305,
00044 
00045       StatusBadRequest = 400,
00046       StatusUnauthorised = 401,
00047       StatusPaymentRequired = 402,
00048       StatusForbidden = 403,
00049       StatusNotFound = 404,
00050       StatusMethodNotAllowed = 405,
00051       // TODO: 406 - 415
00052       
00053       StatusInternalServerError = 500,
00054       StatusNotImplemented = 501
00055       // TODO: 502 - 505
00056    };
00057 
00058    QHttpServletResponse( QIODevice *out, QHttpServletRequest *req );
00059    virtual ~QHttpServletResponse();
00060 
00065    virtual QTextStream *outputStream();
00066 
00068    void setStatus( int status ) { stat = status; }
00069 
00071    int status() const { return stat; }
00072 
00074    void addCookie( QCookie *cookie );
00075 
00077    virtual QHttpServletRequest *request() const {
00078       return (QHttpServletRequest *) QServletResponse::request();
00079    }
00080    
00081    //
00082    // Convenience methods for sending standard responses.
00083    //
00084 
00086    virtual bool sendMessage( const QString &msg=QString::null );
00087 
00089    virtual bool sendError( int status, const QString &msg=QString::null );
00090 
00092    virtual bool sendRedirect( const QString &location );
00093 
00094    //
00095    // HTTP header methods.
00096    //
00097 
00099 
00100    void setHeader( const QString &name, const QString &value );
00101    void setHeader( const QString &name, int value );
00102    void setHeader( const QString &name, const QDateTime &value );
00104 
00106    void sendHeaders( QTextStream *out );
00107 
00108    static QString statusString( int status );
00109 private:
00110    int stat;
00111    QMap<QString,QString> headers; // name -> value
00112 };
00113 
00114 #endif // QHTTPSERVLETRESPONSE_H
00115 
00116 // Local Variables:
00117 // c-basic-offset: 3
00118 // End:
00119 

Generated on Wed Apr 9 23:50:21 2003 for QXServlet by doxygen1.2.17