2 * @file HTTP_ClientRequestHandler.h
4 * @author Martin Corino <mcorino@remedy.nl>
7 #ifndef ACE_HTTP_CLIENT_REQUEST_HANDLER_H
8 #define ACE_HTTP_CLIENT_REQUEST_HANDLER_H
10 #include /**/ "ace/pre.h"
12 #include /**/ "ace/config-all.h"
14 #if !defined (ACE_LACKS_PRAGMA_ONCE)
16 #endif /* ACE_LACKS_PRAGMA_ONCE */
18 #include "ace/Synch_Traits.h"
19 #include "ace/Singleton.h"
20 #include "ace/Thread_Mutex.h"
21 #include "ace/INet/INet_Export.h"
22 #include "ace/INet/IOS_util.h"
23 #include "ace/INet/StreamInterceptor.h"
24 #include "ace/INet/ClientRequestHandler.h"
25 #include "ace/INet/HTTP_Request.h"
26 #include "ace/INet/HTTP_Response.h"
27 #include "ace/INet/HTTP_URL.h"
28 #include "ace/INet/HTTP_Session.h"
30 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
37 * @class ACE_HTTP_SessionHolder
39 * @brief Abstract base class for HTTP session objects.
42 class ACE_INET_Export SessionHolder
43 : public ACE::INet::ConnectionHolder
47 virtual ~SessionHolder();
49 virtual SessionBase
& session () = 0;
52 SessionBase
& operator *();
53 SessionBase
* operator ->();
57 * @class ACE_HTTP_SessionFactory
59 * @brief Abstract base class for HTTP session factories.
62 class ACE_INET_Export SessionFactory
63 : public ACE::INet::ConnectionFactory
67 virtual ~SessionFactory () {}
71 * @class ACE_HTTP_SessionFactory_Impl
73 * @brief Implementation of HTTP session factory.
76 class ACE_INET_Export SessionFactory_Impl
77 : public SessionFactory
80 SessionFactory_Impl ();
81 virtual ~SessionFactory_Impl ();
83 friend class ACE_Singleton
<SessionFactory_Impl
, ACE_SYNCH::NULL_MUTEX
>;
85 static SessionFactory_Impl
& factory_
;
87 class SessionHolder_Impl
: public SessionHolder
90 SessionHolder_Impl ();
91 virtual ~SessionHolder_Impl();
94 virtual SessionBase
& session ();
97 Session_T
<ACE_SYNCH
> session_
;
101 virtual ACE::INet::ConnectionHolder
* create_connection (
102 const ACE::INet::ConnectionKey
& key
) const;
106 * @class ACE_HTTP_SessionFactoryRegistry
108 * @brief Implements registry of HTTP session factories.
111 class ACE_INET_Export SessionFactoryRegistry
114 SessionFactoryRegistry ();
115 ~SessionFactoryRegistry ();
117 friend class ACE_Singleton
<SessionFactoryRegistry
, ACE_SYNCH::MUTEX
>;
120 void register_session_factory (const ACE_CString
& scheme
,
121 SessionFactory
* factory
);
123 SessionFactory
* find_session_factory (const ACE_CString
& scheme
);
125 static SessionFactoryRegistry
& instance ();
128 typedef ACE_Map_Manager
<ACE_CString
,
130 ACE_SYNCH::MUTEX
> TSessionFactoryMap
;
132 TSessionFactoryMap factory_map_
;
136 * @class ACE_HTTP_ClientRequestHandler
138 * @brief This class implements clientside request handling
141 * The class supports the HTTP protocol as specified in RFC 2616.
143 class ACE_INET_Export ClientRequestHandler
144 : public ACE::INet::ClientINetRequestHandler
,
145 public ACE::IOS::StreamInterceptor
148 ClientRequestHandler ();
149 virtual ~ClientRequestHandler ();
151 virtual Request
& request ();
153 virtual const Request
& request () const;
155 virtual Response
& response ();
157 virtual const Response
& response () const;
159 std::ostream
& request_stream ();
161 virtual std::istream
& response_stream ();
163 virtual bool is_response_ok () const;
165 virtual std::istream
& handle_open_request (const ACE::INet::URL_Base
& url
);
167 virtual std::istream
& handle_get_request (const URL
& url
);
169 virtual std::istream& handle_post_request (const URL& url,
170 const PostData& post_data);
172 virtual std::istream& handle_put_request (const URL& url,
173 std::istream* put_data = 0);
176 class ACE_INET_Export HttpConnectionKey
177 : public INetConnectionKey
180 HttpConnectionKey (const ACE_CString
& host
,
182 HttpConnectionKey (const ACE_CString
& proxy_host
,
184 const ACE_CString
& target_host
,
185 u_short target_port
);
186 virtual ~HttpConnectionKey();
188 virtual u_long
hash () const;
190 virtual ACE::INet::ConnectionKey
* duplicate () const;
192 bool is_proxy_connection () const;
194 const ACE_CString
& proxy_target_host () const;
196 u_short
proxy_target_port () const;
199 virtual bool equal (const ACE::INet::ConnectionKey
& key
) const;
202 bool proxy_connection_
;
203 ACE_CString proxy_target_host_
;
204 u_short proxy_target_port_
;
208 virtual void on_eof ();
210 SessionHolder
& session ();
212 void session (SessionHolder
* session
);
214 virtual bool initialize_connection (const ACE_CString
& scheme
,
215 const ACE_CString
& host
,
217 bool proxy_conn
= false,
218 const ACE_CString
& proxy_host
= Request::EMPTY
,
219 u_short proxy_port
= 0);
221 virtual void initialize_request (const URL
& url
, Request
& request
);
223 virtual void handle_request_error (const URL
& url
);
225 virtual void handle_connection_error (const URL
& url
);
227 void release_connection ();
229 void close_connection ();
234 SessionHolder
* session_
;
239 ACE_END_VERSIONED_NAMESPACE_DECL
241 #if defined (__ACE_INLINE__)
242 #include "ace/INet/HTTP_ClientRequestHandler.inl"
245 #include /**/ "ace/post.h"
246 #endif /* ACE_INET_CLIENT_REQUEST_HANDLER_H */