2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FNetHttpHttpResponse.h
20 * @brief This is the header file for the %HttpResponse class.
22 * This header file contains the declarations of the %HttpResponse class.
25 #ifndef _FNET_HTTP_HTTP_RESPONSE_H_
26 #define _FNET_HTTP_HTTP_RESPONSE_H_
28 #include <FBaseColLinkedList.h>
29 #include <FNetHttpHttpTypes.h>
30 #include <FNetHttpHttpHeader.h>
31 #include <FNetHttpHttpMessage.h>
32 #include <FNetHttpHttpCookie.h>
34 namespace Tizen { namespace Net { namespace Http
36 class HttpTransaction;
37 class _HttpResponseImpl;
40 * @brief This class represents a response message.
44 * The %HttpResponse class represents a response message that stores a status code, the status text, and the server version information, as well as
45 * the message headers and body supplied by the HttpMessage base class.
47 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/net/http_connectivity.htm">HTTP Guide</a>.
49 * The following example demonstrates how to use the %HttpResponse class.
56 using namespace Tizen::Base;
57 using namespace Tizen::Net::Http;
60 MyTransactionEventListener::OnTransactionReadyToRead(const Tizen::Net::Http::HttpSession& httpSession,
61 const Tizen::Net::Http::HttpTransaction& httpTransaction, int availableBodyLen)
63 HttpResponse* pResponse = httpTransaction.GetResponse();
65 if (pResponse->GetHttpStatusCode() == HTTP_STATUS_OK)
67 ByteBuffer* pBody = null;
68 String statusText = pResponse->GetStatusText();
69 String version = pResponse->GetVersion();
70 pBody = pResponse->ReadBodyN();
77 //////////////////////////////////////////////////////////////////////////
78 class _OSP_EXPORT_ HttpResponse
85 * Gets the status code from the response header.
87 * @brief <i> [Deprecated] </i>
88 * @deprecated This method is deprecated. Instead of using this method, it is recommended to use the GetHttpStatusCode() method that returns the status code as an integer type.
91 * @return The status code, @n
92 * else @c -1 if an error occurs
93 * @exception E_SUCCESS The method is successful.
94 * @exception E_INVALID_STATE Invoke this method before receiving a response header.
95 * @exception E_INVALID_DATA The status code is not defined.
96 * @remarks The specific error code can be accessed using the GetLastResult() method.
97 * @remarks The @c statusText gives a short textual description of the status code. It is placed after the status code on the first line of the
98 * response. The specific error code can be accessed using the GetLastResult() method.
99 * @see NetHttpStatusCode
100 * @see SetStatusCode()
103 NetHttpStatusCode GetStatusCode(void) const;
106 * Gets the HTTP status code from the response header.
110 * @return The status code, @n
111 * else @c -1 if an error occurs
112 * @exception E_SUCCESS The method is successful.
113 * @exception E_INVALID_STATE Invoke this method before receiving a response header.
114 * @remarks The specific error code can be accessed using the GetLastResult() method.
115 * @remarks The @c statusText gives a short textual description of the status code. It is placed after the status code on the first line of the
117 * @see SetHttpStatusCode()
119 int GetHttpStatusCode(void) const;
122 * Gets a short textual description of the status code from the response header. @n
123 * This description is placed after the status code on the first line of the response.
127 * @return The status description, @n
128 * else an empty string when the status text is not defined
129 * @exception E_SUCCESS The method is successful.
130 * @exception E_INVALID_STATE Invoke this method before receiving a response header.
131 * @exception E_INVALID_DATA The status text is not defined.
132 * @remarks The specific error code can be accessed using the GetLastResult() method.
133 * @see SetStatusText()
135 Tizen::Base::String GetStatusText(void) const;
138 * Gets the version of the protocol used by the server from the response header.
142 * @return The protocol version, @n
143 * else an empty string when the version is not defined
144 * @exception E_SUCCESS The method is successful.
145 * @exception E_INVALID_STATE Invoke this method before receiving a response header.
146 * @exception E_INVALID_DATA The version is not defined.
147 * @remarks The specific error code can be accessed using the GetLastResult() method.
150 Tizen::Base::String GetVersion(void) const;
153 * Gets the HttpHeader object of a response header.
157 * @return The header object, @n
158 * else @c null if the header is not received
159 * @exception E_SUCCESS The method is successful.
160 * @exception E_INVALID_HEADER The header is @c null.
161 * @remarks The specific error code can be accessed using the GetLastResult() method.
163 virtual HttpHeader* GetHeader(void) const;
166 * Gets the message body of the response.
170 * @return The response body object
171 * @exception E_SUCCESS The method is successful.
172 * @exception E_INVALID_STATE Invoke this method before receiving a response body.
173 * @exception E_EMPTY_BODY The requested body is empty.
174 * @exception E_OUT_OF_RANGE The specified @c data size exceeds the maximum range.
175 * @exception E_OUT_OF_MEMORY The memory is insufficient.
176 * @exception E_IO The method has failed to read the data.
177 * @exception E_UNKNOWN An unknown error has occurred.
178 * @remarks The specific error code can be accessed using the GetLastResult() method.
179 * @remarks This method can be invoked several times until there is no more data.
181 virtual Tizen::Base::ByteBuffer* ReadBodyN(void);
184 * Gets the list of cookies received in the response.
188 * @return A list containing HttpCookie instances, @n
189 * else @c null if no cookie is received in the response
190 * @exception E_SUCCESS The method is successful.
191 * @exception E_INVALID_STATE The method invoked is invalid in this state.
192 * @remarks The specific error code can be accessed using the GetLastResult() method.
194 Tizen::Base::Collection::IList* GetCookies(void) const;
198 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
202 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize the instance.
207 * This destructor overrides Tizen::Base::Object::~Object().
211 virtual ~HttpResponse(void);
214 * Initializes this instance of %HttpResponse with the specified parameter.
218 * @return An error code
219 * @param[in] httpTransaction The HTTP transaction
220 * @exception E_SUCCESS The method is successful.
221 * @exception E_OUT_OF_MEMORY The memory is insufficient.
222 * @exception E_INVALID_ARG The specified input parameter is @c null.
223 * @exception E_SYSTEM A system error has occurred.
225 result Construct(const HttpTransaction& httpTransaction);
230 * Sets the status code from the response header.
232 * @brief <i> [Deprecated] </i>
233 * @deprecated This method is deprecated. Instead of using this method, it is recommended to use the SetHttpStatusCode() method that sets
234 * the status code as integer type.
237 * @return An error code
238 * @param[in] statusCode The status code
239 * @exception E_SUCCESS The method is successful.
240 * @exception E_INVALID_ARG The specified input parameter is invalid.
241 * @remarks The @c statusCode element is a 3-digit integer result code of the attempt to understand and satisfy the request. The first digit of the
242 * @c statusCode defines the class of response. The last two digits do not have any categorization role.
243 * @see GetStatusCode()
246 result SetStatusCode(NetHttpStatusCode statusCode);
249 * Sets the status code from the response header.
253 * @return An error code
254 * @param[in] statusCode The status code
255 * @exception E_SUCCESS The method is successful.
256 * @exception E_INVALID_ARG The specified input parameter is invalid.
257 * @remarks The @c statusCode element is a 3-digit integer result code of the attempt to understand and satisfy the request. The first digit of the
258 * @c statusCode defines the class of response. The last two digits do not have any categorization role.
259 * @see GetHttpStatusCode()
261 result SetHttpStatusCode(int statusCode);
264 * Sets the status text from the response header.
268 * @return An error code
269 * @param[in] statusText The status description
270 * @exception E_SUCCESS The method is successful.
271 * @exception E_INVALID_ARG The specified input parameter is @c null.
272 * @remarks The @c statusText gives a short textual description of the status code. This description is placed after the status code on the first
273 * line of the response.
274 * @see GetStatusText()
276 result SetStatusText(const Tizen::Base::String& statusText);
279 * Sets the version of the protocol used by the server from the response header.
283 * @return An error code
284 * @param[in] httpVersion The protocol version
285 * @exception E_SUCCESS The method is successful.
286 * @exception E_INVALID_ARG The specified input parameter is @c null.
289 result SetVersion(const Tizen::Base::String& httpVersion);
292 * Sets the response body.
296 * @return An error code
297 * @param[in] body The message body data
298 * @exception E_SUCCESS The method is successful.
299 * @exception E_OUT_OF_MEMORY The memory is insufficient.
300 * @exception E_INVALID_ARG The specified input parameter is invalid.
301 * @exception E_INVALID_STATE The method invoked is invalid in this state.
302 * @remarks This method can be invoked several times until there is no more data to write.
304 virtual result WriteBody(const Tizen::Base::ByteBuffer& body);
307 * Reads the data from the data communicated.
311 * @return An error code
312 * @param[in] headerLen The header length to read
313 * @param[in] bodyLen The body length to read
314 * @param[out] rcvHeaderLen The received header length
315 * @param[out] rcvBodyLen The received body length
316 * @exception E_SUCCESS The method is successful.
317 * @exception E_IO The method has failed to read the data.
318 * @exception E_OUT_OF_MEMORY The memory is insufficient.
319 * @exception E_INVALID_SESSION The session handle is invalid.
320 * @exception E_INVALID_TRANSACTION The transaction handle is invalid.
321 * @exception E_SYSTEM An internal error has occurred.
322 * @exception E_OUT_OF_RANGE The read data exceeds the maximum range.
323 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation. @n
324 * The comparer has failed to compare keys.
325 * @exception E_INVALID_HEADER An invalid header is received in response.
327 result Read(int headerLen, int bodyLen, int& rcvHeaderLen, int& rcvBodyLen);
330 * Saves the cookie received in the response to %HttpResponse.
334 * @return An error code
335 * @param[in] pHeader A response header
336 * @exception E_SUCCESS The method is successful.
337 * @exception E_INVALID_STATE The method invoked is invalid in this state.
338 * @exception E_OUT_OF_MEMORY The memory is insufficient.
339 * @remarks Transaction events use this method to set the cookie received in the response.
342 result SetCookie(Tizen::Net::Http::HttpHeader* pHeader);
346 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
348 * @param[in] rhs An instance of %HttpResponse
350 HttpResponse(const HttpResponse& rhs);
353 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
355 * @param[in] rhs An instance of %HttpResponse
357 HttpResponse& operator =(const HttpResponse& rhs);
360 friend class _HttpResponseImpl;
361 _HttpResponseImpl* __pHttpResponseImpl;
365 } } } // Tizen::Net::Http
366 #endif // _FNET_HTTP_HTTP_RESPONSE_H_