better streamer
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.0.9 (2012-09-16 14:10:35) stable
|
Version 2.0.9 (2012-09-16 15:38:27) stable
|
||||||
|
|||||||
+12
-9
@@ -13,6 +13,7 @@ import time
|
|||||||
import re
|
import re
|
||||||
import errno
|
import errno
|
||||||
import rewrite
|
import rewrite
|
||||||
|
from rocket import SERVER_SOFTWARE
|
||||||
from http import HTTP
|
from http import HTTP
|
||||||
from contenttype import contenttype
|
from contenttype import contenttype
|
||||||
|
|
||||||
@@ -60,8 +61,8 @@ def stream_file_or_304_or_206(
|
|||||||
fp.close()
|
fp.close()
|
||||||
stat_file = os.stat(static_file)
|
stat_file = os.stat(static_file)
|
||||||
fsize = stat_file[stat.ST_SIZE]
|
fsize = stat_file[stat.ST_SIZE]
|
||||||
mtime = time.strftime('%a, %d %b %Y %H:%M:%S GMT',
|
modified = stat_file[stat.ST_MTIME]
|
||||||
time.gmtime(stat_file[stat.ST_MTIME]))
|
mtime = time.strftime('%a, %d %b %Y %H:%M:%S GMT',time.gmtime(modified))
|
||||||
headers.setdefault('Content-Type', contenttype(static_file))
|
headers.setdefault('Content-Type', contenttype(static_file))
|
||||||
headers.setdefault('Last-Modified', mtime)
|
headers.setdefault('Last-Modified', mtime)
|
||||||
headers.setdefault('Pragma', 'cache')
|
headers.setdefault('Pragma', 'cache')
|
||||||
@@ -91,6 +92,15 @@ def stream_file_or_304_or_206(
|
|||||||
headers['Content-Length'] = '%i' % bytes
|
headers['Content-Length'] = '%i' % bytes
|
||||||
status = 206
|
status = 206
|
||||||
else:
|
else:
|
||||||
|
if request.env.server == SERVER_SOFTWARE and \
|
||||||
|
'gzip' in request.env.http_accept_encoding and\
|
||||||
|
not 'Content-Encoding' in headers:
|
||||||
|
gzipped = static_file + '.gz'
|
||||||
|
if os.path.isfile(gzipped) and os.path.getmtime(gzipped)>modified:
|
||||||
|
static_file = gzipped
|
||||||
|
fsize = os.path.getsize(gzipped)
|
||||||
|
headers['Content-Encoding'] = 'gzip'
|
||||||
|
headers['Vary'] = 'Accept-Encoding'
|
||||||
try:
|
try:
|
||||||
stream = open(static_file, 'rb')
|
stream = open(static_file, 'rb')
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
@@ -106,10 +116,3 @@ def stream_file_or_304_or_206(
|
|||||||
else:
|
else:
|
||||||
wrapped = streamer(stream, chunk_size=chunk_size, bytes=bytes)
|
wrapped = streamer(stream, chunk_size=chunk_size, bytes=bytes)
|
||||||
raise HTTP(status, wrapped, **headers)
|
raise HTTP(status, wrapped, **headers)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user