1 #include "ace/String_Base.h"
2 #include "ace/OS_NS_ctype.h"
3 #include "ace/INet/HTTP_Request.h"
5 #if !defined (__ACE_INLINE__)
6 #include "ace/INet/HTTP_Request.inl"
9 #include "ace/INet/INet_Log.h"
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
18 const ACE_CString
Request::HTTP_GET
= "GET";
19 const ACE_CString
Request::HTTP_HEAD
= "HEAD";
20 const ACE_CString
Request::HTTP_PUT
= "PUT";
21 const ACE_CString
Request::HTTP_POST
= "POST";
22 const ACE_CString
Request::HTTP_OPTIONS
= "OPTIONS";
23 const ACE_CString
Request::HTTP_DELETE
= "DELETE";
24 const ACE_CString
Request::HTTP_TRACE
= "TRACE";
25 const ACE_CString
Request::HTTP_CONNECT
= "CONNECT";
26 const ACE_CString
Request::HOST
= "Host";
27 const ACE_CString
Request::COOKIE
= "Cookie";
28 const ACE_CString
Request::AUTHORIZATION
= "Authorization";
36 Request::Request(const ACE_CString
& version
)
43 Request::Request(const ACE_CString
& method
, const ACE_CString
& uri
)
49 Request::Request(const ACE_CString
& method
, const ACE_CString
& uri
, const ACE_CString
& version
)
60 void Request::set_host(const ACE_CString
& host
, u_short port
)
62 ACE_CString
val(host
);
65 val
+= ACE_OS::itoa (port
, buf
, 10);
66 this->set (HOST
, val
);
69 void Request::add_cookie(const ACE_CString
& cookie
)
71 this->add (COOKIE
, cookie
);
74 void Request::get_cookies(ACE_Array
<ACE_CString
> & cookies
) const
76 this->get_values (COOKIE
, cookies
);
79 void Request::get_credentials(ACE_CString
& scheme
, ACE_CString
& auth_info
) const
81 if (this->has_credentials ())
84 this->get (AUTHORIZATION
, auth
);
85 ACE_CString::ITERATOR
it (auth
);
86 while (!it
.done () && ACE_OS::ace_isspace (*it
))
88 while (!it
.done () && !ACE_OS::ace_isspace (*it
))
90 while (!it
.done () && ACE_OS::ace_isspace (*it
))
97 void Request::set_credentials(const ACE_CString
& scheme
, const ACE_CString
& auth_info
)
99 ACE_CString
val (scheme
);
102 this->set (AUTHORIZATION
, val
);
105 void Request::write(std::ostream
& str
) const
107 str
<< this->method_
.c_str () << " " << this->uri_
.c_str () << " " << this->get_version ().c_str () << "\r\n";
109 INET_DEBUG (6, (LM_DEBUG
, DLINFO
110 ACE_TEXT ("ACE_INet_HTTP: --> %C %C %C\n"),
111 this->method_
.c_str (),
113 this->get_version ().c_str ()));
119 bool Request::read(std::istream
& str
)
121 ACE_CString
method (16, '\0');
122 ACE_CString
uri (128, '\0');
123 ACE_CString
version (16, '\0');
125 int ch
= str
.peek ();
128 str
.get (); // skip to eof
132 while (ACE_OS::ace_isspace (str
.peek ()))
137 ch
= this->read_ws_field (str
, method
, MAX_METHOD_LENGTH
);
138 if (ch
== eof_
|| !ACE_OS::ace_isspace (ch
))
139 return false; // invalid HTTP method string
141 while (ACE_OS::ace_isspace (str
.peek ()))
146 ch
= this->read_ws_field (str
, uri
, MAX_URI_LENGTH
);
147 if (ch
== eof_
|| !ACE_OS::ace_isspace (ch
))
148 return false; // invalid HTTP uri string
150 while (ACE_OS::ace_isspace (str
.peek ()))
155 ch
= this->read_ws_field (str
, version
, MAX_VERSION_LENGTH
);
156 if (ch
== eof_
|| !ACE_OS::ace_isspace (ch
))
157 return false; // invalid HTTP version string
159 while (ch
!= '\n' && ch
!= eof_
)
162 if (!Header::read (str
))
166 while (ch
!= '\n' && ch
!= eof_
)
168 this->set_method (method
);
170 this->set_version(version
);
177 ACE_END_VERSIONED_NAMESPACE_DECL