source: XMLIO_V2/external/include/Poco/Net/HTTPResponse.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 9.1 KB
Line 
1//
2// HTTPResponse.h
3//
4// $Id: //poco/1.3/Net/include/Poco/Net/HTTPResponse.h#2 $
5//
6// Library: Net
7// Package: HTTP
8// Module:  HTTPResponse
9//
10// Definition of the HTTPResponse class.
11//
12// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
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:
21//
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.
28//
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.
36//
37
38
39#ifndef Net_HTTPResponse_INCLUDED
40#define Net_HTTPResponse_INCLUDED
41
42
43#include "Poco/Net/Net.h"
44#include "Poco/Net/HTTPMessage.h"
45#include "Poco/Net/HTTPCookie.h"
46#include "Poco/Timestamp.h"
47#include <vector>
48
49
50namespace Poco {
51namespace Net {
52
53
54class HTTPCookie;
55
56
57class Net_API HTTPResponse: public HTTPMessage
58        /// This class encapsulates an HTTP response
59        /// message.
60        ///
61        /// In addition to the properties common to
62        /// all HTTP messages, a HTTP response has
63        /// status code and a reason phrase.
64{
65public:
66        enum HTTPStatus
67        {
68                HTTP_CONTINUE                        = 100,
69                HTTP_SWITCHING_PROTOCOLS             = 101,
70                HTTP_OK                              = 200,
71                HTTP_CREATED                         = 201,
72                HTTP_ACCEPTED                        = 202,
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,
79                HTTP_FOUND                           = 302,
80                HTTP_SEE_OTHER                       = 303,
81                HTTP_NOT_MODIFIED                    = 304,
82                HTTP_USEPROXY                        = 305,
83                // UNUSED: 306
84                HTTP_TEMPORARY_REDIRECT              = 307,
85                HTTP_BAD_REQUEST                     = 400,
86                HTTP_UNAUTHORIZED                    = 401,
87                HTTP_PAYMENT_REQUIRED                = 402,
88                HTTP_FORBIDDEN                       = 403,
89                HTTP_NOT_FOUND                       = 404,
90                HTTP_METHOD_NOT_ALLOWED              = 405,
91                HTTP_NOT_ACCEPTABLE                  = 406,
92                HTTP_PROXY_AUTHENTICATION_REQUIRED   = 407,
93                HTTP_REQUEST_TIMEOUT                 = 408,
94                HTTP_CONFLICT                        = 409,
95                HTTP_GONE                            = 410,
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
109        };
110
111        HTTPResponse();
112                /// Creates the HTTPResponse with OK status.
113               
114        HTTPResponse(HTTPStatus status, const std::string& reason);
115                /// Creates the HTTPResponse with the given status
116                /// and reason phrase.
117
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.
121               
122        HTTPResponse(HTTPStatus status);
123                /// Creates the HTTPResponse with the given status
124                /// an an appropriate reason phrase.
125
126        HTTPResponse(const std::string& version, HTTPStatus status);
127                /// Creates the HTTPResponse with the given version, status
128                /// an an appropriate reason phrase.
129
130        virtual ~HTTPResponse();
131                /// Destroys the HTTPResponse.
132
133        void setStatus(HTTPStatus status);
134                /// Sets the HTTP status code.
135                ///
136                /// Does not change the reason phrase.
137               
138        HTTPStatus getStatus() const;
139                /// Returns the HTTP status code.
140               
141        void setStatus(const std::string& status);
142                /// Sets the HTTP status code.
143                ///
144                /// The string must contain a valid
145                /// HTTP numerical status code.
146               
147        void setReason(const std::string& reason);
148                /// Sets the HTTP reason phrase.
149               
150        const std::string& getReason() const;
151                /// Returns the HTTP reason phrase.
152
153        void setStatusAndReason(HTTPStatus status, const std::string& reason);
154                /// Sets the HTTP status code and reason phrase.
155               
156        void setStatusAndReason(HTTPStatus status);
157                /// Sets the HTTP status code and reason phrase.
158                ///
159                /// The reason phrase is set according to the status code.
160
161        void setDate(const Poco::Timestamp& dateTime);
162                /// Sets the Date header to the given date/time value.
163               
164        Poco::Timestamp getDate() const;
165                /// Returns the value of the Date header.
166
167        void addCookie(const HTTPCookie& cookie);
168                /// Adds the cookie to the response by
169                /// adding a Set-Cookie header.
170
171        void getCookies(std::vector<HTTPCookie>& cookies) const;
172                /// Returns a vector with all the cookies
173                /// set in the response header.
174                ///
175                /// May throw an exception in case of a malformed
176                /// Set-Cookie header.
177
178        void write(std::ostream& ostr) const;
179                /// Writes the HTTP response to the given
180                /// output stream.
181
182        void read(std::istream& istr);
183                /// Reads the HTTP response from the
184                /// given input stream.
185                ///
186                /// 100 Continue responses are ignored.
187       
188        static const std::string& getReasonForStatus(HTTPStatus status);
189                /// Returns an appropriate reason phrase
190                /// for the given status code.
191
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;
233       
234        static const std::string DATE;
235        static const std::string SET_COOKIE;
236
237private:
238        enum Limits
239        {
240                MAX_VERSION_LENGTH = 8,
241                MAX_STATUS_LENGTH  = 3,
242                MAX_REASON_LENGTH  = 512
243        };
244       
245        HTTPStatus  _status;
246        std::string _reason;
247       
248        HTTPResponse(const HTTPResponse&);
249        HTTPResponse& operator = (const HTTPResponse&);
250};
251
252
253//
254// inlines
255//
256inline HTTPResponse::HTTPStatus HTTPResponse::getStatus() const
257{
258        return _status;
259}
260
261
262inline const std::string& HTTPResponse::getReason() const
263{
264        return _reason;
265}
266
267
268} } // namespace Poco::Net
269
270
271#endif // Net_HTTPResponse_INCLUDED
Note: See TracBrowser for help on using the repository browser.