00001 // $Id: HTTP_URL.cpp 91118 2010-07-17 10:29:57Z mcorino $ 00002 00003 #include "ace/INet/HTTP_URL.h" 00004 00005 #if !defined (__ACE_INLINE__) 00006 #include "ace/INet/HTTP_URL.inl" 00007 #endif 00008 00009 #include "ace/INet/String_IOStream.h" 00010 #include "ace/INet/HTTP_ClientRequestHandler.h" 00011 00012 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00013 00014 namespace ACE 00015 { 00016 namespace HTTP 00017 { 00018 const char* URL::PROTOCOL = "http"; 00019 00020 const ACE_CString& URL::protocol () 00021 { 00022 static const ACE_CString protocol_ (PROTOCOL); 00023 return protocol_; 00024 } 00025 00026 URL::URL () 00027 : URL_INetAuthBase (HTTP_PORT), 00028 proxy_port_ (HTTP_PROXY_PORT) 00029 { 00030 } 00031 00032 URL::URL (const ACE_CString& url_string) 00033 : URL_INetAuthBase (HTTP_PORT), 00034 proxy_port_ (HTTP_PROXY_PORT) 00035 { 00036 this->parse (url_string); 00037 } 00038 00039 URL::URL (const URL& url) 00040 : URL_INetAuthBase (0) 00041 { 00042 *this = url; 00043 } 00044 00045 URL::URL (u_short port) 00046 : URL_INetAuthBase (port), 00047 proxy_port_ (HTTP_PROXY_PORT) 00048 { 00049 } 00050 00051 URL::~URL () 00052 { 00053 } 00054 00055 URL& URL::operator =(const URL& url) 00056 { 00057 this->set_user_info (url.get_user_info ()); 00058 this->set_host (url.get_host ()); 00059 this->set_port (url.get_port ()); 00060 this->set_path (url.get_path ()); 00061 this->set_query (url.get_query ()); 00062 this->set_fragment (url.get_fragment ()); 00063 this->set_proxy (url.get_proxy_host (), url.get_proxy_port ()); 00064 return *this; 00065 } 00066 00067 ACE_CString URL::get_request_uri () const 00068 { 00069 ACE::IOS::CString_OStream sos; 00070 if (!this->proxy_host_.empty ()) 00071 { 00072 sos << this->get_scheme ().c_str () << "://" 00073 << ACE::INet::URL_INetBase::get_host ().c_str (); 00074 if (ACE::INet::URL_INetBase::get_port () != HTTP_PORT) 00075 { 00076 sos << ':' << ACE::INet::URL_INetBase::get_port (); 00077 } 00078 } 00079 // if path is empty we're requesting the root 00080 sos << (this->get_path ().empty () ? 00081 "/" : 00082 this->get_path ().c_str ()); 00083 if (!this->get_query ().empty ()) 00084 sos << '?' << this->get_query ().c_str (); 00085 if (!this->get_fragment ().empty ()) 00086 sos << '#' << this->get_fragment ().c_str (); 00087 return sos.str (); 00088 } 00089 00090 ACE_CString URL::to_string () const 00091 { 00092 ACE::IOS::CString_OStream sos; 00093 sos << this->get_scheme () << "://" 00094 << this->get_authority ().c_str () 00095 << this->get_path ().c_str (); 00096 if (!this->get_query ().empty ()) 00097 sos << '?' << this->get_query ().c_str (); 00098 if (!this->get_fragment ().empty ()) 00099 sos << '#' << this->get_fragment ().c_str (); 00100 return sos.str (); 00101 } 00102 00103 ACE::INet::ClientRequestHandler* URL::create_default_request_handler () const 00104 { 00105 ACE::INet::ClientRequestHandler* prh = 0; 00106 ACE_NEW_NORETURN (prh, ClientRequestHandler ()); 00107 return prh; 00108 } 00109 00110 const URL::Factory& URL::factory_ = *URL::TURLFactorySingleton::instance (); 00111 00112 URL::Factory::Factory () 00113 { 00114 ACE::INet::URL_Base::register_factory (this); 00115 } 00116 00117 URL::Factory::~Factory () 00118 {} 00119 00120 const ACE_CString& URL::Factory::protocol () 00121 { 00122 return URL::protocol (); 00123 } 00124 00125 ACE::INet::URL_Base* URL::Factory::create_from_string (const ACE_CString& url_string) 00126 { 00127 URL* purl = 0; 00128 ACE_NEW_NORETURN (purl, URL (url_string)); 00129 return purl; 00130 } 00131 } 00132 } 00133 00134 ACE_END_VERSIONED_NAMESPACE_DECL