Changes between Version 14 and Version 15 of soc/2007/cgi
- Timestamp:
- May 22, 2008, 4:05:39 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
soc/2007/cgi
v14 v15 1 1 == About == 2 3 : Warning: This page may be out of date, see http://cgi.sf.net/doc for more up-to-date documentation. 2 4 3 5 Below is a partial list of things this project aims to provide: … … 28 30 response resp; // make an empty response 29 31 30 std::string name(req .GET("user_name"));32 std::string name(req[get]["user_name"]); 31 33 resp<< "Hello there, " 32 34 << (name.empty()? "stranger" : name) 33 35 << "!"; 34 resp.send(req.client()); 35 36 return 0; 36 37 return_(resp, req, 0); // send the response and `return 0;' 37 38 } 38 39 }}} … … 57 58 while(a.accept(req) == 0) // no error here 58 59 { 59 std::string name(req .GET("user_name"));60 std::string name(req[get]["user_name"]); 60 61 resp<< "Hello there, " 61 62 << (name.empty()? "stranger" : name) 62 63 << "!"; 64 63 65 resp.send(req.client()); 64 req.close(http::ok); 65 resp.clear(); 66 req.close(http::ok); // note: we can reuse the old request's memory now 67 resp.clear(); // note: we can reuse the old response's memory now 66 68 } 67 69 … … 140 142 141 143 resp<< "Hello, " 142 << req .form("user_name") // this accepts either GET or POST variables.144 << req[form]["user_name"] // this checks either GET or POST variables. 143 145 << "!"; 144 resp.send(req.client()); 145 146 return req.close(http::ok); // we have to explicitly close the requests now. 146 147 return_(resp, req, 0); 147 148 } 148 149 … … 170 171 '''Separation of ```cgi::request``` and ```cgi::response```''': 171 172 172 Th is separation is only a recent change. The main reasoningis that equivalent meta-data exists for both the request and the response (ie. same identifier, different value). Using getters/setters is one idea, although in a large program, there could be a situation where you set a response header and then need to check it later. If everything was done with the ```request``` object then there'd be no clean way to achieve this.173 The original reasoning for this is that equivalent meta-data exists for both the request and the response (ie. same identifier, different value). Using getters/setters is one idea, although in a large program, there could be a situation where you set a response header and then need to check it later. If everything was done with the ```request``` object then there'd be no clean way to achieve this. 173 174 174 175 Having two objects has other advantages: … … 182 183 == Main Classes == 183 184 184 === ```cgi::basic_request<>``` === 185 This holds the data corresponding to the request. It will be specific to a Protocol type and will be aware of how to receive, send and parse data for that Protocol. There will be ```typedef```s for typical usage. 186 187 === ```cgi::request``` === 188 By default, this provides a general (as opposed to generic) access point to any type of request. If constructed with a service object, then the request takes a request from the queue (or blocks until one is available). Default construction initialises a standard cgi environment. 189 190 This generality is achieved using runtime linkage in a similar way to boost::any, although static linking can be forced using a choice of macros which turn ```cgi::request``` into a ```typedef``` for a particular ```cgi::basic_request<>```. 191 192 === ```cgi::response``` === 185 === ```cgi::common::basic_request<>``` === 186 This holds the data corresponding to the request. It will be specific to a Protocol type and will be aware of how to receive, send and parse data for that Protocol. There will be ```typedef```s for typical usage. (ie. ```cgi::request, acgi::request, fcgi::request```). 187 188 === ```cgi::common::response``` === 193 189 This simply holds headers and the content of the response and provides various ways to write to it. Up until it is sent to the user, it is unaware of what it's a response to. This helps keep both library and user code clean and explicit, without being overly verbose and aids significantly with response caching (something this library won't address for now). 194 190 … … 196 192 197 193 === ```cgi::session``` === 198 This will provide simple session data caching. 199 200 === ```cgi::basic_protocol_service<>``` === 194 195 This will provide simple session data caching. NOT YET! 196 197 === ```cgi::common::basic_protocol_service<>``` === 201 198 This is the base class in the library. It is a container for the `io_service`s (from Boost.Asio) that implement asynchronous support and holds lists of current connections and of waiting requests from multiplexed connections. 202 199 203 200 == Important Internal Classes == 204 201 205 === ```cgi:: basic_client<>``` ===202 === ```cgi::common::basic_client<>``` === 206 203 The gateway is the abstraction of the interface with the server. This can vary from just an abstraction of std::cin/cout to a fully multiplexed set of connections, which can themselves be of more than one type. 207 204 208 === ```cgi:: basic_request_acceptor<>``` ===205 === ```cgi::common::basic_request_acceptor<>``` === 209 206 Accepts a new, possibly unloaded request. Before using the request `cgi::basic_request<>::load()` or `cgi::basic_request<>::async_load()` '''must''' be called. 210 207