Check for accept

main
Bob Mottram 2019-11-13 15:41:03 +00:00
parent 1f50dfdc19
commit 7631a814f6
1 changed files with 30 additions and 15 deletions

View File

@ -354,10 +354,13 @@ class PubServer(BaseHTTPRequestHandler):
self.server.systemLanguage, \
self.server.projectVersion)
msg=json.dumps(instanceJson).encode('utf-8')
if 'application/ld+json' in self.headers['Accept']:
self._set_headers('application/ld+json',len(msg),None)
if self.headers.get('Accept'):
if 'application/ld+json' in self.headers['Accept']:
self._set_headers('application/ld+json',len(msg),None)
else:
self._set_headers('application/json',len(msg),None)
else:
self._set_headers('application/json',len(msg),None)
self._set_headers('application/ld+json',len(msg),None)
self._write(msg)
print('instance metadata sent')
return True
@ -368,20 +371,26 @@ class PubServer(BaseHTTPRequestHandler):
# instances a full list of peers would convey a lot of information about
# the interests of a small number of accounts
msg=json.dumps(['mastodon.social',self.server.domainFull]).encode('utf-8')
if 'application/ld+json' in self.headers['Accept']:
self._set_headers('application/ld+json',len(msg),None)
if self.headers.get('Accept'):
if 'application/ld+json' in self.headers['Accept']:
self._set_headers('application/ld+json',len(msg),None)
else:
self._set_headers('application/json',len(msg),None)
else:
self._set_headers('application/json',len(msg),None)
self._set_headers('application/ld+json',len(msg),None)
self._write(msg)
print('instance peers metadata sent')
return True
if self.path.startswith('/api/v1/instance/activity'):
# This is just a dummy result.
msg=json.dumps([]).encode('utf-8')
if 'application/ld+json' in self.headers['Accept']:
self._set_headers('application/ld+json',len(msg),None)
if self.headers.get('Accept'):
if 'application/ld+json' in self.headers['Accept']:
self._set_headers('application/ld+json',len(msg),None)
else:
self._set_headers('application/json',len(msg),None)
else:
self._set_headers('application/json',len(msg),None)
self._set_headers('application/ld+json',len(msg),None)
self._write(msg)
print('instance activity metadata sent')
return True
@ -395,10 +404,13 @@ class PubServer(BaseHTTPRequestHandler):
info=metaDataNodeInfo(self.server.baseDir,self.server.registration,self.server.projectVersion)
if info:
msg=json.dumps(info).encode('utf-8')
if 'application/ld+json' in self.headers['Accept']:
self._set_headers('application/ld+json',len(msg),None)
if self.headers.get('Accept'):
if 'application/ld+json' in self.headers['Accept']:
self._set_headers('application/ld+json',len(msg),None)
else:
self._set_headers('application/json',len(msg),None)
else:
self._set_headers('application/json',len(msg),None)
self._set_headers('application/ld+json',len(msg),None)
self._write(msg)
print('nodeinfo sent')
return True
@ -422,10 +434,13 @@ class PubServer(BaseHTTPRequestHandler):
wfResult=webfingerNodeInfo(self.server.httpPrefix,self.server.domainFull)
if wfResult:
msg=json.dumps(wfResult).encode('utf-8')
if 'application/ld+json' in self.headers['Accept']:
self._set_headers('application/ld+json',len(msg),None)
if self.headers.get('Accept'):
if 'application/ld+json' in self.headers['Accept']:
self._set_headers('application/ld+json',len(msg),None)
else:
self._set_headers('application/json',len(msg),None)
else:
self._set_headers('application/json',len(msg),None)
self._set_headers('application/ld+json',len(msg),None)
self._write(msg)
return True