move example to different port
[multitaskhttpd.git] / proxyapp.py
1 """ This is a proxy server which converts incoming requests into
2 HTTP/1.1 with Keep-Alive set. It maintains a continuous
3 HTTP connection to the server it is proxying for, so that
4 as long as that remote server keeps a process or thread
5 running to serve the continuous stream of requests, that
6 process or thread can keep state information in memory.
7
8 For example, a connection object to a database can be kept
9 around; large complex data structures that are too big to
10 serialise or pass across inter-process boundaries and so on.
11
12 The target proxy HTTP Server *must* support HTTP keep-alives
13 (header "Connection: keep-alive").
14
15 The client (browser, usually) *does not* have to support
16 HTTP keep-alives, or maintain a continuous connection: that
17 action is performed by the proxy.
18
19 However, the only requirements is that the client (browser)
20 *must* support and accept cookies, as the cookie named "session"
21 is used by multitaskhttpd to identify and route the incoming
22 connections through to the correct persistent proxy connection.
23 """
24
25 import multitask
26 import httpd
27 from ProxyServer import ProxyServerRequestHandler
28 from httpd import HTTPServer, App, BaseApp
29
30 class ProxyApp(ProxyServerRequestHandler, BaseApp):
31
32 def __init__(self):
33 BaseApp.__init__(self)
34 ProxyServerRequestHandler.__init__(self)
35 self.proxies = {}
36
37 if __name__ == '__main__':
38 #httpd.set_debug(True)
39 agent = HTTPServer()
40 agent.apps = dict({'*': ProxyApp})
41 agent.start()
42 multitask.run()
43