Mercurial > code > home > repos > homeauto
changeset 708:5b6022beb388
try to detect browser even better, instead of failing the whole request
Ignore-this: 2e228dcc5424533a30a796168f9a0d8
author | drewp@bigasterisk.com |
---|---|
date | Mon, 03 Feb 2020 22:07:20 -0800 |
parents | 41af3ebccdf9 |
children | 95556cacb6e1 |
files | lib/patchablegraph/patchablegraph.py |
diffstat | 1 files changed, 13 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/patchablegraph/patchablegraph.py Mon Feb 03 01:10:56 2020 -0800 +++ b/lib/patchablegraph/patchablegraph.py Mon Feb 03 22:07:20 2020 -0800 @@ -35,7 +35,16 @@ log = logging.getLogger('patchablegraph') -def writeGraphResponse(req, graph, acceptHeader): +def _writeGraphForBrowser(req, graph): + # We think this is a browser, so respond with a live graph view + # (todo) + req.set_header('Content-type', 'text/plain') + lines = graph.serialize(None, format='nquads').splitlines() + lines.sort() + req.write(b'\n'.join(lines)) + + +def _writeGraphResponse(req, graph, acceptHeader: str): if acceptHeader == 'application/nquads': req.set_header('Content-type', 'application/nquads') graph.serialize(req, format='nquads') @@ -43,15 +52,9 @@ req.set_header('Content-type', 'application/ld+json') graph.serialize(req, format='json-ld', indent=2) else: - print(f'acceptHeader {acceptHeader}') if acceptHeader.startswith('text/html'): - # browser; should arrange to pick live view - req.set_header('Content-type', 'text/plain') - lines = graph.serialize(None, format='nquads').splitlines() - lines.sort() - req.write(b'\n'.join(lines)) + _writeGraphForBrowser(req, graph) return - req.set_header('Content-type', 'application/x-trig') graph.serialize(req, format='trig') @@ -149,8 +152,8 @@ def get(self): with self.masterGraph._sendSimpleGraph.time(): - writeGraphResponse(self, self.masterGraph, - self.request.headers.get('accept')) + _writeGraphResponse(self, self.masterGraph, + self.request.headers.get('accept', '')) class CycloneGraphEventsHandler(cyclone.sse.SSEHandler):