Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / protocols / ace / INet / HTTP_Response.cpp
bloba3f5d1309d69fdf85ac7ffe9fe909506d45d04ad
1 #include "ace/OS_NS_stdlib.h"
2 #include "ace/OS_NS_ctype.h"
3 #include "ace/String_Base.h"
4 #include "ace/INet/HTTP_Response.h"
6 #if !defined (__ACE_INLINE__)
7 #include "ace/INet/HTTP_Response.inl"
8 #endif
10 #include "ace/INet/INet_Log.h"
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 namespace ACE
17 namespace HTTP
19 const ACE_CString Response::COOKIE = "Set-Cookie";
21 Response::Response()
25 Response::Response(const Status& status)
26 : status_ (status)
30 Response::Response(const ACE_CString& version, const Status& status)
31 : Header (version), status_ (status)
35 Response::~Response()
39 void Response::add_cookie(const ACE_CString & cookie)
41 this->add (COOKIE, cookie);
44 void Response::get_cookies(ACE_Array<ACE_CString> & cookies) const
46 this->get_values (COOKIE, cookies);
49 void Response::write(ostream& str) const
51 str << this->get_version ().c_str () << " "
52 << static_cast<int>(this->status_.get_status ()) << " "
53 << this->status_.get_reason ().c_str () << "\r\n";
54 Header::write (str);
55 str << "\r\n";
58 bool Response::read(istream& str)
60 ACE_CString version;
61 ACE_CString status;
62 ACE_CString reason;
64 int ch = str.peek ();
65 if (ch == eof_)
67 str.get (); // skip to eof
68 return false;
70 // skip whitespace
71 while (ACE_OS::ace_isspace (str.peek ()))
73 str.get ();
75 // get version
76 ch = this->read_ws_field (str, version, MAX_VERSION_LENGTH);
77 if (ch == eof_ || !ACE_OS::ace_isspace (ch))
78 return false; // invalid HTTP version string
79 // skip whitespace
80 while (ACE_OS::ace_isspace (str.peek ()))
82 str.get ();
84 // get status
85 ch = this->read_ws_field (str, status, MAX_STATUS_LENGTH);
86 if (ch == eof_ || !ACE_OS::ace_isspace (ch))
87 return false; // invalid HTTP status code
88 // skip whitespace
89 while (ACE_OS::ace_isspace (str.peek ()))
91 str.get ();
93 // get reason
94 ch = this->read_field (str, reason, MAX_REASON_LENGTH, '\r');
95 if (ch == '\r')
96 ch = str.get (); // get lf
97 if (ch != '\n')
98 return false; // HTTP reason string too long
100 INET_DEBUG (6, (LM_DEBUG, DLINFO
101 ACE_TEXT ("ACE_INet_HTTP: <-- %C %C %C\n"),
102 version.c_str (),
103 status.c_str (),
104 reason.c_str()));
106 // get header lines
107 if (!Header::read (str))
108 return false;
109 // skip empty line
110 ch = str.get ();
111 while (ch != '\n' && ch != eof_)
112 ch = str.get ();
113 this->set_version(version);
114 this->status_.set_status (status);
115 this->status_.set_reason (reason);
116 return true;
122 ACE_END_VERSIONED_NAMESPACE_DECL