-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirector.py
29 lines (27 loc) · 1001 Bytes
/
redirector.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
from google.appengine.ext import webapp
import wsgiref.handlers
import datetime, time
import logging, os
class RedirectHandler(webapp.RequestHandler):
ruler_data = open(os.path.join(os.path.dirname(__file__), 'ruler.html')).read()
def get(self):
logging.info(self.request.path)
if '/ruler.html' != self.request.path:
self.redirect("http://www.rulernow.com/ruler.html")
else:
self.response.headers['Content-type'] = 'text/html'
self.response.headers['Expires'] = wsgiref.handlers.format_date_time(
time.mktime((datetime.datetime.now() + datetime.timedelta(days=7)).
timetuple()))
self.response.headers['Cache-Control'] = 'public, max-age=%d'%(60*60*24*7)
self.response.out.write(self.ruler_data)
def main():
application = webapp.WSGIApplication(
[
(r'/', RedirectHandler),
(r'/ruler.html', RedirectHandler),
],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()