00001 // $Id: HTTP_SessionBase.h 91118 2010-07-17 10:29:57Z mcorino $ 00002 00003 /** 00004 * @file HTTP_SessionBase.h 00005 * 00006 * @author Martin Corino <mcorino@remedy.nl> 00007 */ 00008 00009 #ifndef ACE_HTTP_SESSION_BASE_H 00010 #define ACE_HTTP_SESSION_BASE_H 00011 00012 #include /**/ "ace/pre.h" 00013 00014 #include "ace/SString.h" 00015 #include "ace/Countdown_Time.h" 00016 #include "ace/Synch_Options.h" 00017 #include "ace/INet/INet_Export.h" 00018 #include "ace/INet/HTTP_Request.h" 00019 #include "ace/INet/HTTP_Response.h" 00020 #include "ace/INet/HTTP_IOStream.h" 00021 00022 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00023 00024 namespace ACE 00025 { 00026 namespace HTTP 00027 { 00028 /** 00029 * @class ACE_HTTP_SessionBase 00030 * 00031 * @brief Abstract base class for HTTP(S) sessions. 00032 * 00033 */ 00034 class ACE_INET_Export SessionBase 00035 { 00036 public: 00037 SessionBase (u_short port, 00038 bool keep_alive = false); 00039 00040 SessionBase (u_short port, 00041 const ACE_Time_Value& timeout, 00042 bool keep_alive = false, 00043 const ACE_Time_Value* alive_timeout = 0); 00044 00045 virtual ~SessionBase (); 00046 00047 void set_keep_alive (bool f); 00048 00049 bool keep_alive () const; 00050 00051 virtual bool is_connected () const = 0; 00052 00053 void set_host (const ACE_CString& host, 00054 u_short port); 00055 00056 void set_host (const ACE_CString& host); 00057 00058 void set_port (u_short port); 00059 00060 void set_proxy_target (const ACE_CString& host, u_short port); 00061 00062 const ACE_CString& get_host () const; 00063 00064 u_short get_port () const; 00065 00066 bool is_proxy_connection () const; 00067 00068 const ACE_CString& get_proxy_target_host () const; 00069 00070 u_short get_proxy_target_port () const; 00071 00072 bool connect (bool use_reactor = false); 00073 00074 std::ostream& send_request (Request& request); 00075 00076 std::ostream& request_stream (); 00077 00078 std::ostream& request_stream (ACE::IOS::StreamInterceptor& interceptor); 00079 00080 std::istream& receive_response (Response& response); 00081 00082 std::istream& response_stream (); 00083 00084 std::istream& response_stream (ACE::IOS::StreamInterceptor& interceptor); 00085 00086 void close (); 00087 00088 protected: 00089 00090 bool reconnect_needed (); 00091 00092 void close_streams (); 00093 00094 virtual bool connect_i (const ACE_Synch_Options& sync_opt) = 0; 00095 00096 virtual void close_i () = 0; 00097 00098 virtual std::iostream& sock_stream () = 0; 00099 00100 enum 00101 { 00102 DEFAULT_TIMEOUT = 30, // sec 00103 DEFAULT_KEEP_ALIVE_TIMEOUT = 8 // sec 00104 }; 00105 00106 ACE_CString host_; 00107 u_short port_; 00108 bool proxy_connection_; 00109 ACE_CString proxy_target_host_; 00110 u_short proxy_target_port_; 00111 00112 bool reactive_; 00113 IStream* in_stream_; 00114 OStream* out_stream_; 00115 ACE_Time_Value http_timeout_; 00116 ACE_Time_Value keep_alive_timeout_; 00117 ACE_Time_Value reconnect_timer_; 00118 ACE_Countdown_Time reconnect_countdown_; 00119 bool keep_alive_; 00120 bool needs_reconnect_; 00121 bool cannot_reconnect_; 00122 bool expects_response_body_; 00123 }; 00124 } 00125 } 00126 00127 ACE_END_VERSIONED_NAMESPACE_DECL 00128 00129 #if defined (__ACE_INLINE__) 00130 #include "ace/INet/HTTP_SessionBase.inl" 00131 #endif 00132 00133 #include /**/ "ace/post.h" 00134 #endif /* ACE_HTTP_SESSION_BASE_H */