forked from indymedia/epicyon
Include length and etag in head
parent
c1f098db8f
commit
3ff2d27697
85
daemon.py
85
daemon.py
|
@ -386,6 +386,12 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._set_headers_base(fileFormat,length,cookie)
|
self._set_headers_base(fileFormat,length,cookie)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
|
||||||
|
def _set_headers_head(self,fileFormat: str,length: int,etag: str) -> None:
|
||||||
|
self._set_headers_base(fileFormat,length,None)
|
||||||
|
if etag:
|
||||||
|
self.send_header('ETag',etag)
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
def _set_headers_etag(self,mediaFilename: str,fileFormat: str, \
|
def _set_headers_etag(self,mediaFilename: str,fileFormat: str, \
|
||||||
data,cookie: str) -> None:
|
data,cookie: str) -> None:
|
||||||
self._set_headers_base(fileFormat,len(data),cookie)
|
self._set_headers_base(fileFormat,len(data),cookie)
|
||||||
|
@ -3507,31 +3513,60 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._benchmarkGETtimings(GETstartTime,GETtimings,55)
|
self._benchmarkGETtimings(GETstartTime,GETtimings,55)
|
||||||
|
|
||||||
def do_HEAD(self):
|
def do_HEAD(self):
|
||||||
if self.path.endswith('.png'):
|
checkPath=self.path
|
||||||
self._set_headers('image/png',-1,None)
|
etag=None
|
||||||
return
|
fileLength=-1
|
||||||
if self.path.endswith('.jpg') or self.path.endswith('.jpeg'):
|
|
||||||
self._set_headers('image/jpeg',-1,None)
|
if '/media/' in self.path:
|
||||||
return
|
if self.path.endswith('.png') or \
|
||||||
if self.path.endswith('.gif'):
|
self.path.endswith('.jpg') or \
|
||||||
self._set_headers('image/gif',-1,None)
|
self.path.endswith('.gif') or \
|
||||||
return
|
self.path.endswith('.webp') or \
|
||||||
if self.path.endswith('.webp'):
|
self.path.endswith('.mp4') or \
|
||||||
self._set_headers('image/webp',-1,None)
|
self.path.endswith('.ogv') or \
|
||||||
return
|
self.path.endswith('.mp3') or \
|
||||||
if self.path.endswith('.mp4'):
|
self.path.endswith('.ogg'):
|
||||||
self._set_headers('video/mp4',-1,None)
|
mediaStr=self.path.split('/media/')[1]
|
||||||
return
|
mediaFilename= \
|
||||||
if self.path.endswith('.ogv'):
|
self.server.baseDir+'/media/'+mediaStr
|
||||||
self._set_headers('video/ogv',-1,None)
|
if os.path.isfile(mediaFilename):
|
||||||
return
|
checkPath=mediaFilename
|
||||||
if self.path.endswith('.mp3'):
|
fileLength=os.path.getsize(mediaFilename)
|
||||||
self._set_headers('audio/mpeg',-1,None)
|
if os.path.isfile(mediaFilename+'.etag'):
|
||||||
return
|
try:
|
||||||
if self.path.endswith('.ogg'):
|
with open(mediaFilename+'.etag', 'r') as etagFile:
|
||||||
self._set_headers('audio/ogg',-1,None)
|
etag = etagFile.read()
|
||||||
return
|
except:
|
||||||
self._set_headers('application/json',-1,None)
|
pass
|
||||||
|
else:
|
||||||
|
with open(mediaFilename, 'rb') as avFile:
|
||||||
|
mediaBinary = avFile.read()
|
||||||
|
etag=sha1(data).hexdigest()
|
||||||
|
try:
|
||||||
|
with open(mediaFilename+'.etag', 'w') as etagFile:
|
||||||
|
etagFile.write(etag)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
mediaFileType='application/json'
|
||||||
|
if checkPath.endswith('.png'):
|
||||||
|
mediaFileType='image/png'
|
||||||
|
elif checkPath.endswith('.jpg'):
|
||||||
|
mediaFileType='image/jpeg'
|
||||||
|
elif checkPath.endswith('.gif'):
|
||||||
|
mediaFileType='image/gif'
|
||||||
|
elif checkPath.endswith('.webp'):
|
||||||
|
mediaFileType='image/webp'
|
||||||
|
elif checkPath.endswith('.mp4'):
|
||||||
|
mediaFileType='video/mp4'
|
||||||
|
elif checkPath.endswith('.ogv'):
|
||||||
|
mediaFileType='video/ogv'
|
||||||
|
elif checkPath.endswith('.mp3'):
|
||||||
|
mediaFileType='audio/mpeg'
|
||||||
|
elif checkPath.endswith('.ogg'):
|
||||||
|
mediaFileType='audio/ogg'
|
||||||
|
|
||||||
|
self._set_headers_head(mediaFileType,fileLength,etag)
|
||||||
|
|
||||||
def _receiveNewPostProcess(self,authorized: bool, \
|
def _receiveNewPostProcess(self,authorized: bool, \
|
||||||
postType: str,path: str,headers: {},
|
postType: str,path: str,headers: {},
|
||||||
|
|
Loading…
Reference in New Issue