]>
Commit | Line | Data |
---|---|---|
1d924d97 CP |
1 | from twisted.web import resource, server, static, http |
2 | from twisted.internet import error, reactor | |
85f01e3f | 3 | import engines |
85f01e3f | 4 | import mimetypes |
1d924d97 | 5 | import config |
9e769c12 CP |
6 | |
7 | class RootResource(resource.Resource): | |
d65fe45f CP |
8 | def getChild(self, name, request): |
9 | if name == "": | |
2b8e1a88 | 10 | name = "qui.html" |
d65fe45f CP |
11 | return self.primaryChild.getChild(name, request) |
12 | ||
1d924d97 CP |
13 | # we do NOT use the built-in timeOut mixin as it's very very buggy! |
14 | class TimeoutHTTPChannel(http.HTTPChannel): | |
15 | timeout = config.HTTP_REQUEST_TIMEOUT | |
16 | ||
17 | def connectionMade(self): | |
18 | self.customTimeout = reactor.callLater(self.timeout, self.timeoutOccured) | |
19 | http.HTTPChannel.connectionMade(self) | |
20 | ||
21 | def timeoutOccured(self): | |
22 | self.customTimeout = None | |
23 | self.transport.loseConnection() | |
24 | ||
25 | def cancelTimeout(self): | |
26 | if self.customTimeout is not None: | |
27 | try: | |
28 | self.customTimeout.cancel() | |
29 | self.customTimeout = None | |
30 | except error.AlreadyCalled: | |
31 | pass | |
32 | ||
33 | def connectionLost(self, reason): | |
34 | self.cancelTimeout() | |
35 | http.HTTPChannel.connectionLost(self, reason) | |
36 | ||
9e769c12 | 37 | class RootSite(server.Site): |
1d924d97 CP |
38 | # we do this ourselves as the built in timeout stuff is really really buggy |
39 | protocol = TimeoutHTTPChannel | |
40 | ||
9e769c12 | 41 | def __init__(self, path, *args, **kwargs): |
d65fe45f | 42 | root = RootResource() |
9e769c12 | 43 | server.Site.__init__(self, root, *args, **kwargs) |
d65fe45f | 44 | |
85f01e3f CP |
45 | services = {} |
46 | services["StaticEngine"] = root.primaryChild = engines.StaticEngine(path) | |
28c8008e | 47 | |
85f01e3f CP |
48 | def register(service, path, *args, **kwargs): |
49 | sobj = service("/" + path, *args, **kwargs) | |
50 | services[service.__name__] = sobj | |
51 | root.putChild(path, sobj) | |
52 | ||
53 | register(engines.AJAXEngine, "e") | |
54 | register(engines.FeedbackEngine, "feedback") | |
55 | register(engines.AuthgateEngine, "auth") | |
56 | register(engines.AdminEngine, "adminengine", services) | |
57 | ||
28c8008e | 58 | mimetypes.types_map[".ico"] = "image/vnd.microsoft.icon" |