4
// $Id: //poco/1.2/Net/include/Poco/Net/HTTPResponse.h#1 $
8
// Module: HTTPResponse
10
// Definition of the HTTPResponse class.
12
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
15
// Permission is hereby granted, free of charge, to any person or organization
16
// obtaining a copy of the software and accompanying documentation covered by
17
// this license (the "Software") to use, reproduce, display, distribute,
18
// execute, and transmit the Software, and to prepare derivative works of the
19
// Software, and to permit third-parties to whom the Software is furnished to
20
// do so, all subject to the following:
22
// The copyright notices in the Software and this entire statement, including
23
// the above license grant, this restriction and the following disclaimer,
24
// must be included in all copies of the Software, in whole or in part, and
25
// all derivative works of the Software, unless such copies or derivative
26
// works are solely in the form of machine-executable object code generated by
27
// a source language processor.
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35
// DEALINGS IN THE SOFTWARE.
39
#ifndef Net_HTTPResponse_INCLUDED
40
#define Net_HTTPResponse_INCLUDED
43
#include "Poco/Net/Net.h"
44
#include "Poco/Net/HTTPMessage.h"
45
#include "Poco/Net/HTTPCookie.h"
46
#include "Poco/Timestamp.h"
57
class Net_API HTTPResponse: public HTTPMessage
58
/// This class encapsulates an HTTP response
61
/// In addition to the properties common to
62
/// all HTTP messages, a HTTP response has
63
/// status code and a reason phrase.
69
HTTP_SWITCHING_PROTOCOLS = 101,
73
HTTP_NONAUTHORITATIVE = 203,
74
HTTP_NO_CONTENT = 204,
75
HTTP_RESET_CONTENT = 205,
76
HTTP_PARTIAL_CONTENT = 206,
77
HTTP_MULTIPLE_CHOICES = 300,
78
HTTP_MOVED_PERMANENTLY = 301,
81
HTTP_NOT_MODIFIED = 304,
84
HTTP_TEMPORARY_REDIRECT = 307,
85
HTTP_BAD_REQUEST = 400,
86
HTTP_UNAUTHORIZED = 401,
87
HTTP_PAYMENT_REQUIRED = 402,
90
HTTP_METHOD_NOT_ALLOWED = 405,
91
HTTP_NOT_ACCEPTABLE = 406,
92
HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
93
HTTP_REQUEST_TIMEOUT = 408,
96
HTTP_LENGTH_REQUIRED = 411,
97
HTTP_PRECONDITION_FAILED = 412,
98
HTTP_REQUESTENTITYTOOLARGE = 413,
99
HTTP_REQUESTURITOOLONG = 414,
100
HTTP_UNSUPPORTEDMEDIATYPE = 415,
101
HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
102
HTTP_EXPECTATION_FAILED = 417,
103
HTTP_INTERNAL_SERVER_ERROR = 500,
104
HTTP_NOT_IMPLEMENTED = 501,
105
HTTP_BAD_GATEWAY = 502,
106
HTTP_SERVICE_UNAVAILABLE = 503,
107
HTTP_GATEWAY_TIMEOUT = 504,
108
HTTP_VERSION_NOT_SUPPORTED = 505
112
/// Creates the HTTPResponse with OK status.
114
HTTPResponse(HTTPStatus status, const std::string& reason);
115
/// Creates the HTTPResponse with the given status
116
/// and reason phrase.
118
HTTPResponse(const std::string& version, HTTPStatus status, const std::string& reason);
119
/// Creates the HTTPResponse with the given version, status
120
/// and reason phrase.
122
HTTPResponse(HTTPStatus status);
123
/// Creates the HTTPResponse with the given status
124
/// an an appropriate reason phrase.
126
HTTPResponse(const std::string& version, HTTPStatus status);
127
/// Creates the HTTPResponse with the given version, status
128
/// an an appropriate reason phrase.
130
virtual ~HTTPResponse();
131
/// Destroys the HTTPResponse.
133
void setStatus(HTTPStatus status);
134
/// Sets the HTTP status code.
136
/// Does not change the reason phrase.
138
HTTPStatus getStatus() const;
139
/// Returns the HTTP status code.
141
void setStatus(const std::string& status);
142
/// Sets the HTTP status code.
144
/// The string must contain a valid
145
/// HTTP numerical status code.
147
void setReason(const std::string& reason);
148
/// Sets the HTTP reason phrase.
150
const std::string& getReason() const;
151
/// Returns the HTTP reason phrase.
153
void setStatusAndReason(HTTPStatus status, const std::string& reason);
154
/// Sets the HTTP status code and reason phrase.
156
void setStatusAndReason(HTTPStatus status);
157
/// Sets the HTTP status code and reason phrase.
159
/// The reason phrase is set according to the status code.
161
void setDate(const Poco::Timestamp& dateTime);
162
/// Sets the Date header to the given date/time value.
164
Poco::Timestamp getDate() const;
165
/// Returns the value of the Date header.
167
void addCookie(const HTTPCookie& cookie);
168
/// Adds the cookie to the response by
169
/// adding a Set-Cookie header.
171
void getCookies(std::vector<HTTPCookie>& cookies) const;
172
/// Returns a vector with all the cookies
173
/// set in the response header.
175
/// May throw an exception in case of a malformed
176
/// Set-Cookie header.
178
void write(std::ostream& ostr) const;
179
/// Writes the HTTP response to the given
182
void read(std::istream& istr);
183
/// Reads the HTTP response from the
184
/// given input stream.
186
/// 100 Continue responses are ignored.
188
static const std::string& getReasonForStatus(HTTPStatus status);
189
/// Returns an appropriate reason phrase
190
/// for the given status code.
192
static const std::string HTTP_REASON_CONTINUE;
193
static const std::string HTTP_REASON_SWITCHING_PROTOCOLS;
194
static const std::string HTTP_REASON_OK;
195
static const std::string HTTP_REASON_CREATED;
196
static const std::string HTTP_REASON_ACCEPTED;
197
static const std::string HTTP_REASON_NONAUTHORITATIVE;
198
static const std::string HTTP_REASON_NO_CONTENT;
199
static const std::string HTTP_REASON_RESET_CONTENT;
200
static const std::string HTTP_REASON_PARTIAL_CONTENT;
201
static const std::string HTTP_REASON_MULTIPLE_CHOICES;
202
static const std::string HTTP_REASON_MOVED_PERMANENTLY;
203
static const std::string HTTP_REASON_FOUND;
204
static const std::string HTTP_REASON_SEE_OTHER;
205
static const std::string HTTP_REASON_NOT_MODIFIED;
206
static const std::string HTTP_REASON_USEPROXY;
207
static const std::string HTTP_REASON_TEMPORARY_REDIRECT;
208
static const std::string HTTP_REASON_BAD_REQUEST;
209
static const std::string HTTP_REASON_UNAUTHORIZED;
210
static const std::string HTTP_REASON_PAYMENT_REQUIRED;
211
static const std::string HTTP_REASON_FORBIDDEN;
212
static const std::string HTTP_REASON_NOT_FOUND;
213
static const std::string HTTP_REASON_METHOD_NOT_ALLOWED;
214
static const std::string HTTP_REASON_NOT_ACCEPTABLE;
215
static const std::string HTTP_REASON_PROXY_AUTHENTICATION_REQUIRED;
216
static const std::string HTTP_REASON_REQUEST_TIMEOUT;
217
static const std::string HTTP_REASON_CONFLICT;
218
static const std::string HTTP_REASON_GONE;
219
static const std::string HTTP_REASON_LENGTH_REQUIRED;
220
static const std::string HTTP_REASON_PRECONDITION_FAILED;
221
static const std::string HTTP_REASON_REQUESTENTITYTOOLARGE;
222
static const std::string HTTP_REASON_REQUESTURITOOLONG;
223
static const std::string HTTP_REASON_UNSUPPORTEDMEDIATYPE;
224
static const std::string HTTP_REASON_REQUESTED_RANGE_NOT_SATISFIABLE;
225
static const std::string HTTP_REASON_EXPECTATION_FAILED;
226
static const std::string HTTP_REASON_INTERNAL_SERVER_ERROR;
227
static const std::string HTTP_REASON_NOT_IMPLEMENTED;
228
static const std::string HTTP_REASON_BAD_GATEWAY;
229
static const std::string HTTP_REASON_SERVICE_UNAVAILABLE;
230
static const std::string HTTP_REASON_GATEWAY_TIMEOUT;
231
static const std::string HTTP_REASON_VERSION_NOT_SUPPORTED;
232
static const std::string HTTP_REASON_UNKNOWN;
234
static const std::string DATE;
235
static const std::string SET_COOKIE;
240
MAX_VERSION_LENGTH = 8,
241
MAX_STATUS_LENGTH = 3,
242
MAX_REASON_LENGTH = 512
253
inline HTTPResponse::HTTPStatus HTTPResponse::getStatus() const
259
inline const std::string& HTTPResponse::getReason() const
265
} } // namespace Poco::Net
268
#endif // Net_HTTPResponse_INCLUDED