]>
Commit | Line | Data |
---|---|---|
1 | from twisted.web import resource, server, static, error | |
2 | from qwebirc.util.gziprequest import GZipRequest | |
3 | import qwebirc.util as util | |
4 | import pprint | |
5 | from adminengine import AdminEngineAction | |
6 | ||
7 | # TODO, cache gzip stuff | |
8 | cache = {} | |
9 | def clear_cache(): | |
10 | global cache | |
11 | cache = {} | |
12 | ||
13 | def apply_gzip(request): | |
14 | accept_encoding = request.getHeader('accept-encoding') | |
15 | if accept_encoding: | |
16 | encodings = accept_encoding.split(',') | |
17 | for encoding in encodings: | |
18 | name = encoding.split(';')[0].strip() | |
19 | if name == 'gzip': | |
20 | request = GZipRequest(request) | |
21 | return request | |
22 | ||
23 | class StaticEngine(static.File): | |
24 | isLeaf = False | |
25 | hit = util.HitCounter() | |
26 | ||
27 | def __init__(self, *args, **kwargs): | |
28 | static.File.__init__(self, *args, **kwargs) | |
29 | ||
30 | def render(self, request): | |
31 | self.hit(request) | |
32 | request = apply_gzip(request) | |
33 | return static.File.render(self, request) | |
34 | ||
35 | @property | |
36 | def adminEngine(self): | |
37 | return { | |
38 | #"GZip cache": [ | |
39 | #("Contents: %s" % pprint.pformat(list(cache.keys())),)# AdminEngineAction("clear", d)) | |
40 | #], | |
41 | "Hits": [ | |
42 | (self.hit,), | |
43 | ] | |
44 | } | |
45 | ||
46 | def directoryListing(self): | |
47 | return error.ForbiddenResource() |