1 | // |
---|
2 | // HTTPMessage.h |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/Net/include/Poco/Net/HTTPMessage.h#2 $ |
---|
5 | // |
---|
6 | // Library: Net |
---|
7 | // Package: HTTP |
---|
8 | // Module: HTTPMessage |
---|
9 | // |
---|
10 | // Definition of the HTTPMessage 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_HTTPMessage_INCLUDED |
---|
40 | #define Net_HTTPMessage_INCLUDED |
---|
41 | |
---|
42 | |
---|
43 | #include "Poco/Net/Net.h" |
---|
44 | #include "Poco/Net/MessageHeader.h" |
---|
45 | |
---|
46 | |
---|
47 | namespace Poco { |
---|
48 | namespace Net { |
---|
49 | |
---|
50 | |
---|
51 | class MediaType; |
---|
52 | |
---|
53 | |
---|
54 | class Net_API HTTPMessage: public MessageHeader |
---|
55 | /// The base class for HTTPRequest and HTTPResponse. |
---|
56 | /// |
---|
57 | /// Defines the common properties of all HTTP messages. |
---|
58 | /// These are version, content length, content type |
---|
59 | /// and transfer encoding. |
---|
60 | { |
---|
61 | public: |
---|
62 | void setVersion(const std::string& version); |
---|
63 | /// Sets the HTTP version for this message. |
---|
64 | |
---|
65 | const std::string& getVersion() const; |
---|
66 | /// Returns the HTTP version for this message. |
---|
67 | |
---|
68 | void setContentLength(int length); |
---|
69 | /// Sets the Content-Length header. |
---|
70 | /// |
---|
71 | /// If length is UNKNOWN_CONTENT_LENGTH, removes |
---|
72 | /// the Content-Length header. |
---|
73 | |
---|
74 | int getContentLength() const; |
---|
75 | /// Returns the content length for this message, |
---|
76 | /// which may be UNKNOWN_CONTENT_LENGTH if |
---|
77 | /// no Content-Length header is present. |
---|
78 | |
---|
79 | void setTransferEncoding(const std::string& transferEncoding); |
---|
80 | /// Sets the transfer encoding for this message. |
---|
81 | /// |
---|
82 | /// The value should be either IDENTITY_TRANSFER_CODING |
---|
83 | /// or CHUNKED_TRANSFER_CODING. |
---|
84 | |
---|
85 | const std::string& getTransferEncoding() const; |
---|
86 | /// Returns the transfer encoding used for this |
---|
87 | /// message. |
---|
88 | /// |
---|
89 | /// Normally, this is the value of the Transfer-Encoding |
---|
90 | /// header field. If no such field is present, |
---|
91 | /// returns IDENTITY_TRANSFER_CODING. |
---|
92 | |
---|
93 | void setChunkedTransferEncoding(bool flag); |
---|
94 | /// If flag is true, sets the Transfer-Encoding header to |
---|
95 | /// chunked. Otherwise, removes the Transfer-Encoding |
---|
96 | /// header. |
---|
97 | |
---|
98 | bool getChunkedTransferEncoding() const; |
---|
99 | /// Returns true if the Transfer-Encoding header is set |
---|
100 | /// and its value is chunked. |
---|
101 | |
---|
102 | void setContentType(const std::string& mediaType); |
---|
103 | /// Sets the content type for this message. |
---|
104 | /// |
---|
105 | /// Specify NO_CONTENT_TYPE to remove the |
---|
106 | /// Content-Type header. |
---|
107 | |
---|
108 | void setContentType(const MediaType& mediaType); |
---|
109 | /// Sets the content type for this message. |
---|
110 | |
---|
111 | const std::string& getContentType() const; |
---|
112 | /// Returns the content type for this message. |
---|
113 | /// |
---|
114 | /// If no Content-Type header is present, |
---|
115 | /// returns UNKNOWN_CONTENT_TYPE. |
---|
116 | |
---|
117 | void setKeepAlive(bool keepAlive); |
---|
118 | /// Sets the value of the Connection header field. |
---|
119 | /// |
---|
120 | /// The value is set to "Keep-Alive" if keepAlive is |
---|
121 | /// true, or to "Close" otherwise. |
---|
122 | |
---|
123 | bool getKeepAlive() const; |
---|
124 | /// Returns true if |
---|
125 | /// * the message has a Connection header field and its value is "Keep-Alive" |
---|
126 | /// * the message is a HTTP/1.1 message and not Connection header is set |
---|
127 | /// Returns false otherwise. |
---|
128 | |
---|
129 | static const std::string HTTP_1_0; |
---|
130 | static const std::string HTTP_1_1; |
---|
131 | |
---|
132 | static const std::string IDENTITY_TRANSFER_ENCODING; |
---|
133 | static const std::string CHUNKED_TRANSFER_ENCODING; |
---|
134 | |
---|
135 | static const int UNKNOWN_CONTENT_LENGTH; |
---|
136 | static const std::string UNKNOWN_CONTENT_TYPE; |
---|
137 | |
---|
138 | static const std::string CONTENT_LENGTH; |
---|
139 | static const std::string CONTENT_TYPE; |
---|
140 | static const std::string TRANSFER_ENCODING; |
---|
141 | static const std::string CONNECTION; |
---|
142 | |
---|
143 | static const std::string CONNECTION_KEEP_ALIVE; |
---|
144 | static const std::string CONNECTION_CLOSE; |
---|
145 | |
---|
146 | static const std::string EMPTY; |
---|
147 | |
---|
148 | protected: |
---|
149 | HTTPMessage(); |
---|
150 | /// Creates the HTTPMessage with version HTTP/1.0. |
---|
151 | |
---|
152 | HTTPMessage(const std::string& version); |
---|
153 | /// Creates the HTTPMessage and sets |
---|
154 | /// the version. |
---|
155 | |
---|
156 | virtual ~HTTPMessage(); |
---|
157 | /// Destroys the HTTPMessage. |
---|
158 | |
---|
159 | private: |
---|
160 | HTTPMessage(const HTTPMessage&); |
---|
161 | HTTPMessage& operator = (const HTTPMessage&); |
---|
162 | |
---|
163 | std::string _version; |
---|
164 | }; |
---|
165 | |
---|
166 | |
---|
167 | // |
---|
168 | // inlines |
---|
169 | // |
---|
170 | inline const std::string& HTTPMessage::getVersion() const |
---|
171 | { |
---|
172 | return _version; |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | } } // namespace Poco::Net |
---|
177 | |
---|
178 | |
---|
179 | #endif // Net_HTTPMessage_INCLUDED |
---|