Go to the documentation of this file.00001
00002
00003 #include "ace/OS_NS_stdlib.h"
00004 #include "ace/OS_NS_ctype.h"
00005 #include "ace/String_Base.h"
00006 #include "ace/INet/HTTP_Response.h"
00007
00008 #if !defined (__ACE_INLINE__)
00009 #include "ace/INet/HTTP_Response.inl"
00010 #endif
00011
00012 #include "ace/INet/INet_Log.h"
00013
00014 ACE_RCSID(NET_CLIENT,ACE_HTTP_Response,"$Id: HTTP_Response.cpp 90891 2010-06-28 09:55:39Z mcorino $")
00015
00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00017
00018 namespace ACE
00019 {
00020 namespace HTTP
00021 {
00022
00023 const ACE_CString Response::COOKIE = "Set-Cookie";
00024
00025 Response::Response()
00026 {
00027 }
00028
00029 Response::Response(const Status& status)
00030 : status_ (status)
00031 {
00032 }
00033
00034 Response::Response(const ACE_CString& version, const Status& status)
00035 : Header (version), status_ (status)
00036 {
00037 }
00038
00039 Response::~Response()
00040 {
00041 }
00042
00043 void Response::add_cookie(const ACE_CString & cookie)
00044 {
00045 this->add (COOKIE, cookie);
00046 }
00047
00048 void Response::get_cookies(ACE_Array<ACE_CString> & cookies) const
00049 {
00050 this->get_values (COOKIE, cookies);
00051 }
00052
00053 void Response::write(ostream& str) const
00054 {
00055 str << this->get_version ().c_str () << " "
00056 << static_cast<int>(this->status_.get_status ()) << " "
00057 << this->status_.get_reason ().c_str () << "\r\n";
00058 Header::write (str);
00059 str << "\r\n";
00060 }
00061
00062 bool Response::read(istream& str)
00063 {
00064 ACE_CString version;
00065 ACE_CString status;
00066 ACE_CString reason;
00067
00068 int ch = str.peek ();
00069 if (ch == eof_)
00070 {
00071 str.get ();
00072 return false;
00073 }
00074
00075 while (ACE_OS::ace_isspace (str.peek ()))
00076 {
00077 str.get ();
00078 }
00079
00080 ch = this->read_ws_field (str, version, MAX_VERSION_LENGTH);
00081 if (ch == eof_ || !ACE_OS::ace_isspace (ch))
00082 return false;
00083
00084 while (ACE_OS::ace_isspace (str.peek ()))
00085 {
00086 str.get ();
00087 }
00088
00089 ch = this->read_ws_field (str, status, MAX_STATUS_LENGTH);
00090 if (ch == eof_ || !ACE_OS::ace_isspace (ch))
00091 return false;
00092
00093 while (ACE_OS::ace_isspace (str.peek ()))
00094 {
00095 str.get ();
00096 }
00097
00098 ch = this->read_field (str, reason, MAX_REASON_LENGTH, '\r');
00099 if (ch == '\r')
00100 ch = str.get ();
00101 if (ch != '\n')
00102 return false;
00103
00104 INET_DEBUG (6, (LM_DEBUG, DLINFO
00105 ACE_TEXT ("ACE_INet_HTTP: <-- %C %C %C\n"),
00106 version.c_str (),
00107 status.c_str (),
00108 reason.c_str()));
00109
00110
00111 if (!Header::read (str))
00112 return false;
00113
00114 ch = str.get ();
00115 while (ch != '\n' && ch != eof_)
00116 ch = str.get ();
00117 this->set_version(version);
00118 this->status_.set_status (status);
00119 this->status_.set_reason (reason);
00120 return true;
00121 }
00122
00123 }
00124 }
00125
00126 ACE_END_VERSIONED_NAMESPACE_DECL