No calling domain

main
Bob Mottram 2021-09-12 12:39:20 +01:00
parent 028f4897bb
commit cff94e7781
1 changed files with 25 additions and 6 deletions

View File

@ -721,7 +721,8 @@ class PubServer(BaseHTTPRequestHandler):
self.send_header('Content-type', fileFormat) self.send_header('Content-type', fileFormat)
if length > -1: if length > -1:
self.send_header('Content-Length', str(length)) self.send_header('Content-Length', str(length))
self.send_header('Host', callingDomain) if callingDomain:
self.send_header('Host', callingDomain)
if permissive: if permissive:
self.send_header('Access-Control-Allow-Origin', '*') self.send_header('Access-Control-Allow-Origin', '*')
return return
@ -6471,7 +6472,7 @@ class PubServer(BaseHTTPRequestHandler):
mediaBinary = avFile.read() mediaBinary = avFile.read()
self._set_headers_etag(mediaFilename, mediaFileType, self._set_headers_etag(mediaFilename, mediaFileType,
mediaBinary, None, mediaBinary, None,
callingDomain, True, None, True,
lastModifiedTimeStr) lastModifiedTimeStr)
self._write(mediaBinary) self._write(mediaBinary)
self._benchmarkGETtimings(GETstartTime, GETtimings, self._benchmarkGETtimings(GETstartTime, GETtimings,
@ -6487,7 +6488,18 @@ class PubServer(BaseHTTPRequestHandler):
""" """
if '.owl' in path or '.rdf' in path or '.json' in path: if '.owl' in path or '.rdf' in path or '.json' in path:
ontologyStr = path.split('/ontologies/')[1].replace('#', '') ontologyStr = path.split('/ontologies/')[1].replace('#', '')
ontologyFilename = baseDir + '/ontology/DFC/' + ontologyStr ontologyFilename = None
ontologyFileType = 'application/rdf+xml'
if ontologyStr.startswith('DFC_'):
ontologyFilename = baseDir + '/ontology/DFC/' + ontologyStr
elif ontologyStr.endswith('.json'):
ontologyStr = ontologyStr.replace('/data/', '')
ontologyFilename = baseDir + '/ontology/' + ontologyStr
else:
self._404()
return
if ontologyStr.endswith('.json'):
ontologyFileType = 'application/ld+json'
if os.path.isfile(ontologyFilename): if os.path.isfile(ontologyFilename):
ontologyFile = None ontologyFile = None
with open(ontologyFilename, 'r') as fp: with open(ontologyFilename, 'r') as fp:
@ -6495,9 +6507,16 @@ class PubServer(BaseHTTPRequestHandler):
if ontologyFile: if ontologyFile:
ontologyFile = \ ontologyFile = \
ontologyFile.replace('static.datafoodconsortium.org', ontologyFile.replace('static.datafoodconsortium.org',
self.server.domainFull) callingDomain)
if not callingDomain.endswith('.i2p') and \
not callingDomain.endswith('.onion'):
ontologyFile = \
ontologyFile.replace('http://' +
self.server.domainFull,
'https://' +
self.server.domainFull)
msg = ontologyFile.encode('utf-8') msg = ontologyFile.encode('utf-8')
self._set_headers('application/rdf+xml', len(msg), self._set_headers(ontologyFileType, len(msg),
None, callingDomain, False) None, callingDomain, False)
self._write(msg) self._write(msg)
self._benchmarkGETtimings(GETstartTime, GETtimings, self._benchmarkGETtimings(GETstartTime, GETtimings,
@ -11240,7 +11259,7 @@ class PubServer(BaseHTTPRequestHandler):
mediaBinary = avFile.read() mediaBinary = avFile.read()
self._set_headers_etag(avatarFilename, mediaImageType, self._set_headers_etag(avatarFilename, mediaImageType,
mediaBinary, None, mediaBinary, None,
callingDomain, True, None, True,
lastModifiedTimeStr) lastModifiedTimeStr)
self._write(mediaBinary) self._write(mediaBinary)
self._benchmarkGETtimings(GETstartTime, GETtimings, self._benchmarkGETtimings(GETstartTime, GETtimings,