1 """twisted server for CubicWeb web applications |
1 """twisted server for CubicWeb web applications |
2 |
2 |
3 :organization: Logilab |
3 :organization: Logilab |
4 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 __docformat__ = "restructuredtext en" |
7 __docformat__ = "restructuredtext en" |
8 |
8 |
9 import sys |
9 import sys |
10 import select |
10 import select |
11 |
11 from time import mktime |
12 from mx.DateTime import today, RelativeDate |
12 from datetime import date, timedelta |
13 |
13 |
14 from twisted.application import service, strports |
14 from twisted.application import service, strports |
15 from twisted.internet import reactor, task, threads |
15 from twisted.internet import reactor, task, threads |
16 from twisted.internet.defer import maybeDeferred |
16 from twisted.internet.defer import maybeDeferred |
17 from twisted.web2 import channel, http, server, iweb |
17 from twisted.web2 import channel, http, server, iweb |
60 def setExpireHeader(response): |
60 def setExpireHeader(response): |
61 response = iweb.IResponse(response) |
61 response = iweb.IResponse(response) |
62 # Don't provide additional resource information to error responses |
62 # Don't provide additional resource information to error responses |
63 if response.code < 400: |
63 if response.code < 400: |
64 # the HTTP RFC recommands not going further than 1 year ahead |
64 # the HTTP RFC recommands not going further than 1 year ahead |
65 expires = today() + RelativeDate(months=6) |
65 expires = date.today() + timedelta(days=6*30) |
66 response.headers.setHeader('Expires', int(expires.ticks())) |
66 response.headers.setHeader('Expires', mktime(expires.timetuple())) |
67 return response |
67 return response |
68 d = maybeDeferred(super(LongTimeExpiringFile, self).renderHTTP, request) |
68 d = maybeDeferred(super(LongTimeExpiringFile, self).renderHTTP, request) |
69 return d.addCallback(setExpireHeader) |
69 return d.addCallback(setExpireHeader) |
70 |
70 |
71 |
71 |