QtWebApp
httpresponse.h
Go to the documentation of this file.
1 
6 #ifndef HTTPRESPONSE_H
7 #define HTTPRESPONSE_H
8 
9 #include <QMap>
10 #include <QString>
11 #include <QTcpSocket>
12 #include "httpglobal.h"
13 #include "httpcookie.h"
14 
15 namespace stefanfrings {
16 
36 class DECLSPEC HttpResponse {
37  Q_DISABLE_COPY(HttpResponse)
38 public:
39 
44  HttpResponse(QTcpSocket *socket);
45 
52  void setHeader(const QByteArray name, const QByteArray value);
53 
60  void setHeader(const QByteArray name, const int value);
61 
63  QMap<QByteArray,QByteArray>& getHeaders();
64 
66  QMap<QByteArray,HttpCookie>& getCookies();
67 
72  void setStatus(const int statusCode, const QByteArray description=QByteArray());
73 
75  int getStatusCode() const;
76 
90  void write(const QByteArray data, const bool lastPart=false);
91 
95  bool hasSentLastPart() const;
96 
101  void setCookie(const HttpCookie& cookie);
102 
108  void redirect(const QByteArray& url);
109 
115  void flush();
116 
121  bool isConnected() const;
122 
123 private:
124 
126  QMap<QByteArray,QByteArray> headers;
127 
129  QTcpSocket* socket;
130 
132  int statusCode;
133 
135  QByteArray statusText;
136 
138  bool sentHeaders;
139 
141  bool sentLastPart;
142 
144  bool chunkedMode;
145 
147  QMap<QByteArray,HttpCookie> cookies;
148 
150  bool writeToSocket(QByteArray data);
151 
157  void writeHeaders();
158 
159 };
160 
161 } // end of namespace
162 
163 #endif // HTTPRESPONSE_H
HTTP cookie as defined in RFC 2109.
Definition: httpcookie.h:21
This object represents a HTTP response, used to return something to the web client.
Definition: httpresponse.h:36