#include <HTTP_Request.h>
Public Member Functions | |
Request () | |
Constructor; creates a GET / HTTP/1.0 HTTP request. | |
Request (const ACE_CString &version) | |
Constructor; creates a GET request with given version. | |
Request (const ACE_CString &method, const ACE_CString &uri) | |
Constructor; creates a HTTP/1.0 request with given method and URI. | |
Request (const ACE_CString &method, const ACE_CString &uri, const ACE_CString &version) | |
Constructor; creates an HTTP request with given method, URI and version. | |
virtual | ~Request () |
Destructor. | |
void | reset () |
Reset the request object. | |
void | reset (const ACE_CString &version) |
void | reset (const ACE_CString &method, const ACE_CString &uri) |
void | reset (const ACE_CString &method, const ACE_CString &uri, const ACE_CString &version) |
void | set_method (const ACE_CString &method) |
Set the method. | |
const ACE_CString & | get_method () const |
Return the method. | |
void | set_URI (const ACE_CString &uri) |
Set the request URI. | |
const ACE_CString & | get_URI () const |
Return the request URI. | |
void | set_host (const ACE_CString &host) |
Set the Host header field. | |
void | set_host (const ACE_CString &host, u_short port) |
bool | has_host () const |
Returns true if Host header field has been set. | |
ACE_CString | get_host () const |
Returns the value of the Host header field. | |
void | add_cookie (const ACE_CString &cookie) |
Adds a Cookie header. | |
void | get_cookies (ACE_Array< ACE_CString > &cookies) const |
Get cookies from Cookie header(s). | |
bool | has_credentials () const |
void | get_credentials (ACE_CString &scheme, ACE_CString &auth_info) const |
Returns the authentication scheme and authentication information. | |
void | set_credentials (const ACE_CString &scheme, const ACE_CString &auth_info) |
Set the authentication scheme and information. | |
void | write (std::ostream &str) const |
Writes the HTTP request to the given stream. | |
bool | read (std::istream &str) |
Static Public Attributes | |
static const ACE_CString | HTTP_GET = "GET" |
static const ACE_CString | HTTP_HEAD = "HEAD" |
static const ACE_CString | HTTP_PUT = "PUT" |
static const ACE_CString | HTTP_POST = "POST" |
static const ACE_CString | HTTP_OPTIONS = "OPTIONS" |
static const ACE_CString | HTTP_DELETE = "DELETE" |
static const ACE_CString | HTTP_TRACE = "TRACE" |
static const ACE_CString | HTTP_CONNECT = "CONNECT" |
static const ACE_CString | HOST = "Host" |
static const ACE_CString | COOKIE = "Cookie" |
static const ACE_CString | AUTHORIZATION = "Authorization" |
Private Types | |
enum | Limits { MAX_METHOD_LENGTH = 32, MAX_URI_LENGTH = 4096, MAX_VERSION_LENGTH = 8 } |
Limits for reading a header. More... | |
Private Attributes | |
ACE_CString | method_ |
ACE_CString | uri_ |
Definition at line 31 of file HTTP_Request.h.
enum ACE::HTTP::Request::Limits [private] |
Limits for reading a header.
Reimplemented from ACE::INet::HeaderBase.
Definition at line 119 of file HTTP_Request.h.
{ MAX_METHOD_LENGTH = 32, MAX_URI_LENGTH = 4096, MAX_VERSION_LENGTH = 8 };
ACE::HTTP::Request::Request | ( | ) |
ACE::HTTP::Request::Request | ( | const ACE_CString & | version | ) |
ACE::HTTP::Request::Request | ( | const ACE_CString & | method, | |
const ACE_CString & | uri | |||
) |
Constructor; creates a HTTP/1.0 request with given method and URI.
Definition at line 47 of file HTTP_Request.cpp.
ACE::HTTP::Request::Request | ( | const ACE_CString & | method, | |
const ACE_CString & | uri, | |||
const ACE_CString & | version | |||
) |
ACE::HTTP::Request::~Request | ( | ) | [virtual] |
void ACE::HTTP::Request::add_cookie | ( | const ACE_CString & | cookie | ) |
Adds a Cookie header.
Definition at line 73 of file HTTP_Request.cpp.
void ACE::HTTP::Request::get_cookies | ( | ACE_Array< ACE_CString > & | cookies | ) | const |
Get cookies from Cookie header(s).
Definition at line 78 of file HTTP_Request.cpp.
{ this->get_values (COOKIE, cookies); }
void ACE::HTTP::Request::get_credentials | ( | ACE_CString & | scheme, | |
ACE_CString & | auth_info | |||
) | const |
Returns the authentication scheme and authentication information.
Definition at line 83 of file HTTP_Request.cpp.
{ if (this->has_credentials ()) { ACE_CString auth; this->get (AUTHORIZATION, auth); ACE_CString::ITERATOR it (auth); while (!it.done () && ACE_OS::ace_isspace (*it)) ++it; while (!it.done () && !ACE_OS::ace_isspace (*it)) scheme += *it++; while (!it.done () && ACE_OS::ace_isspace (*it)) ++it; while (!it.done ()) auth_info += *it++; } }
ACE_CString ACE::HTTP::Request::get_host | ( | ) | const [inline] |
Returns the value of the Host header field.
Definition at line 85 of file HTTP_Request.inl.
{ ACE_CString val; this->get (HOST, val); return val; }
const ACE_CString & ACE::HTTP::Request::get_method | ( | ) | const [inline] |
const ACE_CString & ACE::HTTP::Request::get_URI | ( | ) | const [inline] |
bool ACE::HTTP::Request::has_credentials | ( | ) | const [inline] |
Returns true if the request contains authentication information in the form of an Authorization header.
Definition at line 93 of file HTTP_Request.inl.
{ return this->has (AUTHORIZATION); }
bool ACE::HTTP::Request::has_host | ( | ) | const [inline] |
Returns true if Host header field has been set.
Definition at line 79 of file HTTP_Request.inl.
bool ACE::HTTP::Request::read | ( | std::istream & | str | ) | [virtual] |
Reads the HTTP request from the given stream.
Reimplemented from ACE::INet::HeaderBase.
Definition at line 123 of file HTTP_Request.cpp.
{ ACE_CString method (16, '\0'); ACE_CString uri (128, '\0'); ACE_CString version (16, '\0'); int ch = str.peek (); if (ch == eof_) { str.get (); // skip to eof return false; } // skip whitespace while (ACE_OS::ace_isspace (str.peek ())) { str.get (); } // get method ch = this->read_ws_field (str, method, MAX_METHOD_LENGTH); if (ch == eof_ || !ACE_OS::ace_isspace (ch)) return false; // invalid HTTP method string // skip whitespace while (ACE_OS::ace_isspace (str.peek ())) { str.get (); } // get uri ch = this->read_ws_field (str, uri, MAX_URI_LENGTH); if (ch == eof_ || !ACE_OS::ace_isspace (ch)) return false; // invalid HTTP uri string // skip whitespace while (ACE_OS::ace_isspace (str.peek ())) { str.get (); } // get version ch = this->read_ws_field (str, version, MAX_VERSION_LENGTH); if (ch == eof_ || !ACE_OS::ace_isspace (ch)) return false; // invalid HTTP version string // skip to eol while (ch != '\n' && ch != eof_) ch = str.get (); // get header lines if (!Header::read (str)) return false; // skip empty line ch = str.get (); while (ch != '\n' && ch != eof_) ch = str.get (); this->set_method (method); this->set_URI (uri); this->set_version(version); return true; }
void ACE::HTTP::Request::reset | ( | const ACE_CString & | version | ) | [inline] |
Definition at line 22 of file HTTP_Request.inl.
{ this->clear (); this->set_version (version); this->method_ = HTTP_GET; this->uri_ = "/"; }
void ACE::HTTP::Request::reset | ( | const ACE_CString & | method, | |
const ACE_CString & | uri | |||
) | [inline] |
Definition at line 31 of file HTTP_Request.inl.
{ this->clear (); this->set_version (HTTP_1_0); this->method_ = method; this->uri_ = uri; }
void ACE::HTTP::Request::reset | ( | void | ) | [inline] |
Reset the request object.
Definition at line 13 of file HTTP_Request.inl.
void ACE::HTTP::Request::reset | ( | const ACE_CString & | method, | |
const ACE_CString & | uri, | |||
const ACE_CString & | version | |||
) | [inline] |
Definition at line 40 of file HTTP_Request.inl.
{ this->clear (); this->set_version (version); this->method_ = method; this->uri_ = uri; }
void ACE::HTTP::Request::set_credentials | ( | const ACE_CString & | scheme, | |
const ACE_CString & | auth_info | |||
) |
Set the authentication scheme and information.
Definition at line 101 of file HTTP_Request.cpp.
{ ACE_CString val (scheme); val += " "; val += auth_info; this->set (AUTHORIZATION, val); }
void ACE::HTTP::Request::set_host | ( | const ACE_CString & | host, | |
u_short | port | |||
) |
Definition at line 64 of file HTTP_Request.cpp.
{ ACE_CString val(host); val += ':'; char buf[16]; val += ACE_OS::itoa (port, buf, 10); this->set (HOST, val); }
void ACE::HTTP::Request::set_host | ( | const ACE_CString & | host | ) | [inline] |
Set the Host header field.
Definition at line 73 of file HTTP_Request.inl.
{ this->set (HOST, host); }
void ACE::HTTP::Request::set_method | ( | const ACE_CString & | method | ) | [inline] |
void ACE::HTTP::Request::set_URI | ( | const ACE_CString & | uri | ) | [inline] |
void ACE::HTTP::Request::write | ( | std::ostream & | str | ) | const [virtual] |
Writes the HTTP request to the given stream.
Reimplemented from ACE::INet::HeaderBase.
Definition at line 109 of file HTTP_Request.cpp.
{ str << this->method_.c_str () << " " << this->uri_.c_str () << " " << this->get_version ().c_str () << "\r\n"; INET_DEBUG (6, (LM_DEBUG, DLINFO ACE_TEXT ("ACE_INet_HTTP: --> %C %C %C\n"), this->method_.c_str (), this->uri_.c_str (), this->get_version ().c_str ())); Header::write (str); str << "\r\n"; }
const ACE_CString ACE::HTTP::Request::AUTHORIZATION = "Authorization" [static] |
Definition at line 116 of file HTTP_Request.h.
const ACE_CString ACE::HTTP::Request::COOKIE = "Cookie" [static] |
Definition at line 115 of file HTTP_Request.h.
const ACE_CString ACE::HTTP::Request::HOST = "Host" [static] |
Definition at line 114 of file HTTP_Request.h.
const ACE_CString ACE::HTTP::Request::HTTP_CONNECT = "CONNECT" [static] |
Definition at line 112 of file HTTP_Request.h.
const ACE_CString ACE::HTTP::Request::HTTP_DELETE = "DELETE" [static] |
Definition at line 110 of file HTTP_Request.h.
const ACE_CString ACE::HTTP::Request::HTTP_GET = "GET" [static] |
Definition at line 105 of file HTTP_Request.h.
const ACE_CString ACE::HTTP::Request::HTTP_HEAD = "HEAD" [static] |
Definition at line 106 of file HTTP_Request.h.
const ACE_CString ACE::HTTP::Request::HTTP_OPTIONS = "OPTIONS" [static] |
Definition at line 109 of file HTTP_Request.h.
const ACE_CString ACE::HTTP::Request::HTTP_POST = "POST" [static] |
Definition at line 108 of file HTTP_Request.h.
const ACE_CString ACE::HTTP::Request::HTTP_PUT = "PUT" [static] |
Definition at line 107 of file HTTP_Request.h.
const ACE_CString ACE::HTTP::Request::HTTP_TRACE = "TRACE" [static] |
Definition at line 111 of file HTTP_Request.h.
ACE_CString ACE::HTTP::Request::method_ [private] |
Definition at line 126 of file HTTP_Request.h.
ACE_CString ACE::HTTP::Request::uri_ [private] |
Definition at line 127 of file HTTP_Request.h.