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"
10 #include "ace/INet/INet_Log.h"
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
19 const ACE_CString
Response::COOKIE
= "Set-Cookie";
25 Response::Response(const Status
& status
)
30 Response::Response(const ACE_CString
& version
, const Status
& status
)
31 : Header (version
), status_ (status
)
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";
58 bool Response::read(istream
& str
)
67 str
.get (); // skip to eof
71 while (ACE_OS::ace_isspace (str
.peek ()))
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
80 while (ACE_OS::ace_isspace (str
.peek ()))
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
89 while (ACE_OS::ace_isspace (str
.peek ()))
94 ch
= this->read_field (str
, reason
, MAX_REASON_LENGTH
, '\r');
96 ch
= str
.get (); // get lf
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"),
107 if (!Header::read (str
))
111 while (ch
!= '\n' && ch
!= eof_
)
113 this->set_version(version
);
114 this->status_
.set_status (status
);
115 this->status_
.set_reason (reason
);
122 ACE_END_VERSIONED_NAMESPACE_DECL