Changes between Version 1 and Version 2 of soc/2007/cgi


Ignore:
Timestamp:
May 22, 2007, 3:02:24 PM (15 years ago)
Author:
Darren Garvey
Comment:

starting off the page

Legend:

Unmodified
Added
Removed
Modified
  • soc/2007/cgi

    v1 v2  
    1 In a week, after my exams, the current design decisions about this library will be put up here. If anyone stumbles on here in the meantime, feel free to put up some bullet points.
     1== About ==
    22
    3 Past discussion can be found (starting) here:[[BR]]
    4 http://lists.boost.org/Archives/boost/2007/04/120191.php [[BR]]
    5 http://lists.boost.org/Archives/boost/2007/04/119565.php
     3Below is a partial list of things this project aims to provide:
     4 * Simple access to standard CGI environment variables and input data
     5 * Clean access to request meta-data (ie. 'environment vars') and input data using alternative protocols, such as FastCGI
     6 * Asynchronous read/write support
     7 * A clean way to write to clients without knowledge of the underlying protocol in use
     8
     9== Usage ==
     10
     11First, a standard CGI example:
     12{{{
     13#!cpp
     14int main()
     15{
     16  cgi::request req;   // set up the request
     17  cgi::response resp; // see Design Ideas for more about this
     18
     19  resp<< "Hello, " << req.param<cgi::GET>("user_name") << "!";
     20  resp.send(req);
     21 
     22  return 0;
     23}
     24}}}
     25Using an alternate protocol (FastCGI in this case) will alter the above like so:
     26{{{
     27#!cpp
     28int sub_main(cgi::request req)
     29{
     30  cgi::response resp; // see Design Notes for more about this
     31
     32  resp<< "Hello, " << req.param<cgi::GET>("user_name") << "!";
     33  resp.send(req);
     34
     35  return 0;
     36}
     37
     38int main()
     39{
     40  cgi::fcgi_service service(&sub_main);
     41  service.run();
     42 
     43  return 0;
     44}
     45}}}
     46
     47
     48== Design Notes ==
     49
     50    ''Past discussion can be found (starting) here:[[BR]]
     51    http://lists.boost.org/Archives/boost/2007/04/120191.php [[BR]]
     52    http://lists.boost.org/Archives/boost/2007/04/119565.php''
     53
     54'''Separation of ```cgi::request``` and ```cgi::response```''':
     55
     56This separation is only a recent change. The main reasoning is that meta-data exists for both the request and the response. 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 way to achieve this.
     57
     58Having two objects has other advantages:
     59 * Code is clearer, without being too verbose
     60 * Response caching is easier to implement; code can just cache a ```cgi::response``` since it holds no data relevant to the specific request (note: response caching isn't really part of this project, although ```cgi::session``` will probably provide basic facilities)
     61
     62
     63== Main Classes ==
     64
     65=== ```cgi::basic_request<>``` ===
     66This 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.
     67
     68=== ```cgi::request``` ===
     69By 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.
     70
     71This 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<>```.
     72
     73=== ```cgi::response``` ===
     74This 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 code - 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).
     75
     76=== ```cgi::session``` ===
     77This will provide simple session data caching.
     78
     79=== ```cgi::basic_service<>``` ===
     80This is the main class in the library. There should be specializations for each Protocol and the underlying structure should be generic enough to allow for any type of cgi-like protocol to be 'serviced', without sacrificing efficiency, clarity of code or any of the aims stated in the Design Notes.
     81
     82
     83
     84Since the cache could reside in process memory, shared memory, files or a database, the class should be flexible. The actual data will be held in a ```std::map<std::string, T>```. T should theoretically be generic, so could be ```boost::any``` - this