-
Notifications
You must be signed in to change notification settings - Fork 15
/
pyserve.py
executable file
·44 lines (38 loc) · 1.41 KB
/
pyserve.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
#!/usr/bin/env python
import SimpleHTTPServer
class GZipFriendlyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
MONKEYPATCHED_HEADERS = {
'/d/us_postal_codes.gz': {
'Content-Encoding': 'gzip',
'Content-Type': 'text/csv'
},
'/js/event-data.gz': {
'Content-Encoding': 'gzip',
'Content-Type': 'text/javascript'
},
'/js/jquery.gz': {
'Content-Encoding': 'gzip',
'Content-Type': 'text/javascript'
},
'/js/d3.gz': {
'Content-Encoding': 'gzip',
'Content-Type': 'text/javascript'
},
'/js/deparam.min.gz': {
'Content-Encoding': 'gzip',
'Content-Type': 'text/javascript'
},
'/js/mapbox.gz': {
'Content-Encoding': 'gzip',
'Content-Type': 'text/javascript'
},
}
if self.path in MONKEYPATCHED_HEADERS:
for header, value in MONKEYPATCHED_HEADERS[self.path].iteritems():
self.send_header(header, value)
if __name__ == '__main__':
SimpleHTTPServer.test(HandlerClass=GZipFriendlyRequestHandler)