3 //=============================================================================
7 * @author James Hu and Irfan Pyarali
9 //=============================================================================
12 #ifndef HTTP_HANDLER_H
13 #define HTTP_HANDLER_H
15 // = Forward declarations
17 class HTTP_Handler_Factory
;
19 #include "ace/Asynch_IO.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include "HTTP_Request.h"
26 #include "HTTP_Response.h"
32 * @brief This class is used to implement the HTTP protocol
34 * The HTTP_Handler class is a state based implementation of the
35 * HTTP protocol. Therefore, it can be used synchronously and
36 * asynchronously. It uses an abstract IO class to move between
37 * different HTTP protocol states. It is up to the IO class to
38 * decide on synchronous or asynchronous I/O.
40 class HTTP_Handler
: protected JAWS_IO_Handler
42 // Friend I/O classes. Can call protected methods.
43 friend class JAWS_Synch_IO
;
44 friend class JAWS_Synch_IO_No_Cache
;
45 friend class JAWS_Asynch_IO
;
48 friend class Asynch_HTTP_Handler_Factory
;
49 friend class Synch_HTTP_Handler_Factory
;
50 friend class No_Cache_Synch_HTTP_Handler_Factory
;
54 * The handler is initialized with a connection <handle> of a new
55 * client and any <initial_data> that came across. The
56 * <initial_data> block will be of MAX_REQUEST_SIZE and the number
57 * of bytes in <initial_data> can be found from
58 * <initial_data>.length ()
60 virtual void open (ACE_HANDLE handle
,
61 ACE_Message_Block
&initial_data
);
64 /// The constructor is passed the factory that created <this> and the
65 /// IO mechanism that the handler should use.
66 HTTP_Handler (JAWS_IO
&io
,
67 HTTP_Handler_Factory
&factory
);
70 virtual ~HTTP_Handler ();
72 /// This method is called by the framework when there is a timeout.
73 virtual void timeout ();
76 * This is the termination state of the handler. After successful or
77 * unsuccessful completions, the handler will end up in this state
83 virtual void request_too_long ();
85 /// Reference to the creating factory.
86 HTTP_Handler_Factory
&factory_
;
89 // = Completion methods inherited from <JAWS_IO_Handler>.
91 virtual void read_complete (ACE_Message_Block
&data
);
92 virtual void read_error ();
93 virtual void transmit_file_complete ();
94 virtual void transmit_file_error (int result
);
95 virtual void receive_file_complete ();
96 virtual void receive_file_error (int result
);
97 virtual void write_error ();
98 virtual void confirmation_message_complete ();
99 virtual void error_message_complete ();
104 MAX_SOCKBUFSIZE
= 64 * 1024,
105 MAX_REQUEST_SIZE
= 8192,
111 /// This points to the request sent by the client
112 ACE_Message_Block
*request_data_
;
114 /// I/O handle to the client
117 HTTP_Request request_
;
118 HTTP_Response response_
;
120 /// IO class used by the handler
125 * @class HTTP_Handler_Factory
127 * @brief This class is used to create new HTTP handlers
129 * This is an abstract factory for creating new HTTP handlers.
131 class HTTP_Handler_Factory
135 virtual ~HTTP_Handler_Factory ();
137 /// This creates a new HTTP_Handler
138 virtual HTTP_Handler
*create_http_handler () = 0;
141 * The HTTP handler will call this method from HTTP_Handler::done to
142 * tell the factory to reap up the handler as it is now done with
145 virtual void destroy_http_handler (HTTP_Handler
&handler
,
150 * @class Synch_HTTP_Handler_Factory
152 * @brief This class is used to create new HTTP handlers that will use
155 class Synch_HTTP_Handler_Factory
: public HTTP_Handler_Factory
158 /// This creates a new HTTP_Handler
159 HTTP_Handler
*create_http_handler ();
162 * The HTTP handler will call this method from HTTP_Handler::done to
163 * tell the factory to reap up the handler as it is now done with
166 void destroy_http_handler (HTTP_Handler
&handler
,
170 //--------------Added a factory for SYNCH IO without caching
173 * @class No_Cache_Synch_HTTP_Handler_Factory
175 * @brief This class is used to create new HTTP handlers that will use
176 * Synch IO without caching
178 class No_Cache_Synch_HTTP_Handler_Factory
: public HTTP_Handler_Factory
181 /// This creates a new HTTP_Handler
182 HTTP_Handler
*create_http_handler ();
185 * The HTTP handler will call this method from HTTP_Handler::done to
186 * tell the factory to reap up the handler as it is now done with
189 void destroy_http_handler (HTTP_Handler
&handler
,
195 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO)
197 * @class Asynch_HTTP_Handler_Factory
199 * @brief This class is used to create new HTTP handlers that will use
200 * Asynchronous IO. This only works on Win32.
202 class Asynch_HTTP_Handler_Factory
: public HTTP_Handler_Factory
, public ACE_Service_Handler
206 * The HTTP handler will call this method from HTTP_Handler::done to
207 * tell the factory to reap up the handler as it is now done with
210 void destroy_http_handler (HTTP_Handler
&handler
,
214 * <open> is called by <ACE_Asynch_Acceptor> to initialize a new
215 * instance of ACE_Service_Handler that has been created after the a
216 * new connection is accepted.
218 * This will act as a creation point for new handlers.
220 virtual void open (ACE_HANDLE handle
,
221 ACE_Message_Block
&message_block
);
225 * This method is private as users are not allowed to create new
226 * handlers. New handlers can only be created by the framework when
227 * new client connections arrive.
229 HTTP_Handler
*create_http_handler ();
231 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO */
232 #endif /* HTTP_HANDLER_H */