Commits

Brian Mearns committed 404f924

Utilizing the fpr in serveFile for gonzo_web in order to set the expiration header to almost 1 yr in the future to encourage caching.

Comments (0)

Files changed (1)

 import base64
 import sys
 import time
+from wsgiref.handlers import format_date_time
 import re
 
 from gonzo_out import Output
             self.serveFile(method)
 
     def serveFile(self, method="GET"):
-        parsed = urlparse.urlparse(self.path)
-
         start = None
         end = None
+
+        qs = urlparse.parse_qs(urlparse.urlparse(self.path).query)
+        print self.server.fingerprint(), qs
+        if "fpr" in qs:
+            if qs["fpr"][0] == self.server.fingerprint():
+                #Set an expiration nearly a year inthe future (that's max allowed by HTTP standard).
+                # 31449600 seconds = 364 days.
+                self.send_header("Expires", format_date_time(time.time() + 31449600))
+            
+
         if "Range" in self.headers:
             rstr = self.headers["Range"]
             mobj = re.compile(r'bytes\s*=\s*([0-9]+)?\s*-\s*([0-9]+)?\s*').match(rstr)
         self.__handleRequest("HEAD")
 
     def __handleRequest(self, method):
-        print "--->", self.path
         addr, port = self.client_address
         message = "(%(addr)s:%(port)d) - %(method)s %(path)s" % {
             "addr": addr, "port": port, "method": self.command, "path": self.path
         if self.__contentLength is None:
             self.__contentLength = os.path.getsize(self.__filepath)
         if start is None:
-            if end is not None:
+            if end is None:
                 #Both are none
                 return (None, None, self.__contentLength)