Commit dff53681 authored by Romain Courteaud's avatar Romain Courteaud Committed by Sebastien Robin

Get modification date from btree.

Support no content.
parent 00f696ee
...@@ -123,6 +123,8 @@ class BigFile(File): ...@@ -123,6 +123,8 @@ class BigFile(File):
if range is not None: if range is not None:
ranges = HTTPRangeSupport.parseRange(range) ranges = HTTPRangeSupport.parseRange(range)
data = self._baseGetData()
if if_range is not None: if if_range is not None:
# Only send ranges if the data isn't modified, otherwise send # Only send ranges if the data isn't modified, otherwise send
# the whole object. Support both ETags and Last-Modified dates! # the whole object. Support both ETags and Last-Modified dates!
...@@ -139,10 +141,13 @@ class BigFile(File): ...@@ -139,10 +141,13 @@ class BigFile(File):
try: mod_since=long(DateTime(date).timeTime()) try: mod_since=long(DateTime(date).timeTime())
except: mod_since=None except: mod_since=None
if mod_since is not None: if mod_since is not None:
if self._p_mtime: if data is not None:
last_mod = long(self._p_mtime) last_mod = long(data._p_mtime)
else: else:
last_mod = long(0) if self._p_mtime:
last_mod = long(self._p_mtime)
else:
last_mod = long(0)
if last_mod > mod_since: if last_mod > mod_since:
# Modified, so send a normal response. We delete # Modified, so send a normal response. We delete
# the ranges, which causes us to skip to the 200 # the ranges, which causes us to skip to the 200
...@@ -161,8 +166,10 @@ class BigFile(File): ...@@ -161,8 +166,10 @@ class BigFile(File):
RESPONSE.setHeader('Content-Range', RESPONSE.setHeader('Content-Range',
'bytes */%d' % self.getSize()) 'bytes */%d' % self.getSize())
RESPONSE.setHeader('Accept-Ranges', 'bytes') RESPONSE.setHeader('Accept-Ranges', 'bytes')
RESPONSE.setHeader('Last-Modified', if data is not None:
rfc1123_date(self._p_mtime)) RESPONSE.setHeader('Last-Modified', rfc1123_date(data._p_mtime))
else:
RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Content-Type', self.content_type)
RESPONSE.setHeader('Content-Length', self.getSize()) RESPONSE.setHeader('Content-Length', self.getSize())
RESPONSE.setStatus(416) RESPONSE.setStatus(416)
...@@ -175,8 +182,10 @@ class BigFile(File): ...@@ -175,8 +182,10 @@ class BigFile(File):
start, end = ranges[0] start, end = ranges[0]
size = end - start size = end - start
RESPONSE.setHeader('Last-Modified', if data is not None:
rfc1123_date(self._p_mtime)) RESPONSE.setHeader('Last-Modified', rfc1123_date(data._p_mtime))
else:
RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Content-Type', self.content_type)
RESPONSE.setHeader('Content-Length', size) RESPONSE.setHeader('Content-Length', size)
RESPONSE.setHeader('Accept-Ranges', 'bytes') RESPONSE.setHeader('Accept-Ranges', 'bytes')
...@@ -184,7 +193,6 @@ class BigFile(File): ...@@ -184,7 +193,6 @@ class BigFile(File):
'bytes %d-%d/%d' % (start, end - 1, self.getSize())) 'bytes %d-%d/%d' % (start, end - 1, self.getSize()))
RESPONSE.setStatus(206) # Partial content RESPONSE.setStatus(206) # Partial content
data = self._baseGetData()
if isinstance(data, str): if isinstance(data, str):
RESPONSE.write(data[start:end]) RESPONSE.write(data[start:end])
return True return True
...@@ -209,6 +217,7 @@ class BigFile(File): ...@@ -209,6 +217,7 @@ class BigFile(File):
size = (size + len('%d%d' % (start, end - 1)) + size = (size + len('%d%d' % (start, end - 1)) +
end - start) end - start)
data = self._baseGetData()
# Some clients implement an earlier draft of the spec, they # Some clients implement an earlier draft of the spec, they
# will only accept x-byteranges. # will only accept x-byteranges.
...@@ -216,15 +225,15 @@ class BigFile(File): ...@@ -216,15 +225,15 @@ class BigFile(File):
RESPONSE.setHeader('Content-Length', size) RESPONSE.setHeader('Content-Length', size)
RESPONSE.setHeader('Accept-Ranges', 'bytes') RESPONSE.setHeader('Accept-Ranges', 'bytes')
RESPONSE.setHeader('Last-Modified', if data is not None:
rfc1123_date(self._p_mtime)) RESPONSE.setHeader('Last-Modified', rfc1123_date(data._p_mtime))
else:
RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
RESPONSE.setHeader('Content-Type', RESPONSE.setHeader('Content-Type',
'multipart/%sbyteranges; boundary=%s' % ( 'multipart/%sbyteranges; boundary=%s' % (
draftprefix, boundary)) draftprefix, boundary))
RESPONSE.setStatus(206) # Partial content RESPONSE.setStatus(206) # Partial content
data = self._baseGetData()
for start, end in ranges: for start, end in ranges:
RESPONSE.write('\r\n--%s\r\n' % boundary) RESPONSE.write('\r\n--%s\r\n' % boundary)
RESPONSE.write('Content-Type: %s\r\n' % RESPONSE.write('Content-Type: %s\r\n' %
...@@ -285,6 +294,8 @@ class BigFile(File): ...@@ -285,6 +294,8 @@ class BigFile(File):
RESPONSE.setHeader('Accept-Ranges', 'bytes') RESPONSE.setHeader('Accept-Ranges', 'bytes')
if data is None:
return ''
iterator = data.iterate() iterator = data.iterate()
try: try:
while 1: while 1:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment