From: Brian Candler Date: 2002-10-06T19:05:21+09:00 Subject: CGI sessions as threads? Hello, One of the things which interests me most about Ruby is its built-in threading capability. In particular, I would like to know if anyone has written a library which allows CGI sessions to be modelled as threads? This would make it extremely easy to write interactive CGI applications, as the thread would only see exchanges between itself and its one client. For example, you might start writing a simple login screen like this: ---------------------------------------------------------------------------- retries = 0 begin show 'login_page.htm' u = wait_response retries+=1 end while retries < 3 && u.username!='brian' && u.password!='mypass' if retries >= 3 then show 'goaway.htm' exit end show 'main_menu.htm' u = wait_response # and so on ---------------------------------------------------------------------------- wait_response blocks until the next CGI request (HTTP post) which is associated with this particular thread arrives. It also commits suicide if no response is received within an idle timeout period. There needs to be a central dispatcher which takes an incoming request, checks to see if it has a valid session cookie, and if so dispatches it to the correct thread; if not, then it creates a new thread for it. Perhaps for safety, the 'show' function should set a different cookie every time, to ensure that the user cannot press 'back' multiple times and then submit an out-of-sequence form - or else the server thread should have the option of handling this case itself. Anyway, it seems to me that this ought to be fairly straightforward to implement, so has anybody done this already? I have a lot of Ruby learning to do before I would attempt it myself :-) Regards, Brian Candler.