forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-aspen.py
48 lines (30 loc) · 1.2 KB
/
configure-aspen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from __future__ import unicode_literals
import os
import time
import aspen_sentry
from aspen import log
aspen_sentry.install(website)
website.renderer_default = b"tornado"
def time_request_inbound(request):
request._start = time.time()
def time_request_outbound(response):
start = response.request._start
end = time.time()
elapsed = (end - start) * 1000.0
log("Request served in %.3f ms." % elapsed)
website.hooks.inbound_early += [time_request_inbound]
website.hooks.outbound += [time_request_outbound]
# Collapse /foo/bar/baz.png into /foo/bar%2Fbaz.png.
# ==================================================
# https://github.com/gittip/shields.io/issues/57
def redirect_uncollapsed_paths(request):
if b'%2F' in request.line.uri.path.raw:
request.redirect(request.line.uri.path.raw.replace(b'%2F', b'/'))
website.hooks.inbound_early += [redirect_uncollapsed_paths]
# Up the threadpool size.
# =======================
# Yanked from Gittip. Should upstream this.
def up_minthreads(website):
website.network_engine.cheroot_server.requests.min = \
int(os.environ['ASPEN_THREAD_POOL'])
website.hooks.startup.insert(0, up_minthreads)