Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ACE_HTTP_CLIENT_REQUEST_HANDLER_H
00010 #define ACE_HTTP_CLIENT_REQUEST_HANDLER_H
00011
00012 #include "ace/pre.h"
00013
00014 #include "ace/config-all.h"
00015
00016 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00017 # pragma once
00018 #endif
00019
00020 #include "ace/Synch_Traits.h"
00021 #include "ace/Singleton.h"
00022 #include "ace/Thread_Mutex.h"
00023 #include "ace/INet/INet_Export.h"
00024 #include "ace/INet/IOS_util.h"
00025 #include "ace/INet/StreamInterceptor.h"
00026 #include "ace/INet/ClientRequestHandler.h"
00027 #include "ace/INet/HTTP_Request.h"
00028 #include "ace/INet/HTTP_Response.h"
00029 #include "ace/INet/HTTP_URL.h"
00030 #include "ace/INet/HTTP_Session.h"
00031
00032 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00033
00034 namespace ACE
00035 {
00036 namespace HTTP
00037 {
00038
00039
00040
00041
00042
00043
00044 class ACE_INET_Export SessionHolder
00045 : public ACE::INet::ConnectionHolder
00046 {
00047 protected:
00048 SessionHolder ();
00049 virtual ~SessionHolder();
00050
00051 virtual SessionBase& session () = 0;
00052
00053 public:
00054 SessionBase& operator *();
00055 SessionBase* operator ->();
00056 };
00057
00058
00059
00060
00061
00062
00063
00064 class ACE_INET_Export SessionFactory
00065 : public ACE::INet::ConnectionFactory
00066 {
00067 protected:
00068 SessionFactory () {}
00069 virtual ~SessionFactory () {}
00070 };
00071
00072
00073
00074
00075
00076
00077
00078 class ACE_INET_Export SessionFactory_Impl
00079 : public SessionFactory
00080 {
00081 private:
00082 SessionFactory_Impl ();
00083 virtual ~SessionFactory_Impl ();
00084
00085 friend class ACE_Singleton<SessionFactory_Impl, ACE_SYNCH::NULL_MUTEX>;
00086
00087 static SessionFactory_Impl& factory_;
00088
00089 class SessionHolder_Impl : public SessionHolder
00090 {
00091 public:
00092 SessionHolder_Impl ();
00093 virtual ~SessionHolder_Impl();
00094
00095 protected:
00096 virtual SessionBase& session ();
00097
00098 private:
00099 Session_T<ACE_SYNCH> session_;
00100 };
00101
00102 public:
00103 virtual ACE::INet::ConnectionHolder* create_connection (
00104 const ACE::INet::ConnectionKey& key) const;
00105 };
00106
00107
00108
00109
00110
00111
00112
00113 class ACE_INET_Export SessionFactoryRegistry
00114 {
00115 private:
00116 SessionFactoryRegistry ();
00117 ~SessionFactoryRegistry ();
00118
00119 friend class ACE_Singleton<SessionFactoryRegistry, ACE_SYNCH::MUTEX>;
00120
00121 public:
00122
00123 void register_session_factory (const ACE_CString& scheme,
00124 SessionFactory* factory);
00125
00126 SessionFactory* find_session_factory (const ACE_CString& scheme);
00127
00128 static SessionFactoryRegistry& instance ();
00129
00130 private:
00131 typedef ACE_Map_Manager<ACE_CString,
00132 SessionFactory*,
00133 ACE_SYNCH::MUTEX> TSessionFactoryMap;
00134
00135 TSessionFactoryMap factory_map_;
00136 };
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 class ACE_INET_Export ClientRequestHandler
00147 : public ACE::INet::ClientINetRequestHandler,
00148 public ACE::IOS::StreamInterceptor
00149 {
00150 public:
00151 ClientRequestHandler ();
00152 virtual ~ClientRequestHandler ();
00153
00154 virtual Request& request ();
00155
00156 virtual const Request& request () const;
00157
00158 virtual Response& response ();
00159
00160 virtual const Response& response () const;
00161
00162 std::ostream& request_stream ();
00163
00164 virtual std::istream& response_stream ();
00165
00166 virtual bool is_response_ok () const;
00167
00168 virtual std::istream& handle_open_request (const ACE::INet::URL_Base& url);
00169
00170 virtual std::istream& handle_get_request (const URL& url);
00171
00172
00173
00174
00175
00176
00177
00178
00179 class HttpConnectionKey
00180 : public INetConnectionKey
00181 {
00182 public:
00183 HttpConnectionKey (const ACE_CString& host,
00184 u_short port);
00185 HttpConnectionKey (const ACE_CString& proxy_host,
00186 u_short proxy_port,
00187 const ACE_CString& target_host,
00188 u_short target_port);
00189 virtual ~HttpConnectionKey();
00190
00191 virtual u_long hash () const;
00192
00193 virtual ConnectionKey* duplicate () const;
00194
00195 bool is_proxy_connection () const;
00196
00197 const ACE_CString& proxy_target_host () const;
00198
00199 u_short proxy_target_port () const;
00200
00201 protected:
00202 virtual bool equal (const ConnectionKey& key) const;
00203
00204 private:
00205 bool proxy_connection_;
00206 ACE_CString proxy_target_host_;
00207 u_short proxy_target_port_;
00208 };
00209
00210 protected:
00211 virtual void on_eof ();
00212
00213 SessionHolder& session ();
00214
00215 void session (SessionHolder* session);
00216
00217 virtual bool initialize_connection (const ACE_CString& scheme,
00218 const ACE_CString& host,
00219 u_short port,
00220 bool proxy_conn = false,
00221 const ACE_CString& proxy_host = Request::EMPTY,
00222 u_short proxy_port = 0);
00223
00224 virtual void initialize_request (const URL& url, Request& request);
00225
00226 virtual void handle_request_error (const URL& url);
00227
00228 virtual void handle_connection_error (const URL& url);
00229
00230 void release_connection ();
00231
00232 void close_connection ();
00233
00234 private:
00235 Request request_;
00236 Response response_;
00237 SessionHolder* session_;
00238 };
00239
00240 }
00241 }
00242
00243 ACE_END_VERSIONED_NAMESPACE_DECL
00244
00245 #if defined (__ACE_INLINE__)
00246 #include "ace/INet/HTTP_ClientRequestHandler.inl"
00247 #endif
00248
00249 #include "ace/post.h"
00250 #endif