From b0fff4a8fea922773f1005974bede64cc8215776 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 6 Nov 2026 08:44:46 -0500 Subject: [PATCH] Default to json, and add binary types for screenshot to come down in a more straightforward way --- confluent_server/confluent/httpapi.py | 14 +++++++++++++- confluent_server/confluent/messages.py | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/confluent_server/confluent/httpapi.py b/confluent_server/confluent/httpapi.py index 4852e678..04db394a 100644 --- a/confluent_server/confluent/httpapi.py +++ b/confluent_server/confluent/httpapi.py @@ -443,8 +443,12 @@ def _pick_mimetype(req): return 'text/html', '.html' elif 'Accept' in req.headers and 'application/json' in req.headers['Accept']: return 'application/json; charset=utf-8', '' + elif 'Accept' in req.headers and 'application/octet-stream' in req.headers['Accept']: + return 'application/octet-stream', '' + elif 'Accept' in req.headers and 'image/*' in req.headers['Accept']: + return 'image/*', '' else: - return 'text/html', '' + return 'application/json; charset=utf-8', '' def _assign_consessionid(consolesession): @@ -1115,6 +1119,10 @@ async def resourcehandler_backend(req, make_response): for datum in _assemble_html(hdlr, resource, lquerydict, url, extension): pagecontent += datum + elif mimetype in ('application/octet-stream', 'image/png', 'image/jpeg'): + pagecontent = b'' + async for datum in _assemble_binary(hdlr, resource, url, extension, mimetype): + pagecontent += datum else: async for datum in _assemble_json(hdlr, resource, url, extension): pagecontent += datum @@ -1133,6 +1141,10 @@ async def resourcehandler_backend(req, make_response): await rsp.write(e.get_error_body().encode('utf8')) return rsp +async def _assemble_binary(responses, resource, url, extension, mimetype): + async for rsp in pluginapi.iterate_responses(responses): + yield rsp.binary(mimetype) + def _assemble_html(responses, resource, querydict, url, extension): yield 'HTML API Explorer is discontinued, notify developers if you want this back' return diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index 96efeeeb..10f5f4fa 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -2093,6 +2093,10 @@ class ScreenShot(ConfluentMessage): self.myargs = (imgdata, node, imgformat) self.kvpairs = {node: {'image': {'imgformat': imgformat, 'imgdata': base64.b64encode(imgdata).decode()}}} + def binary(self, mimetype): + if mimetype == 'application/octet-stream': + return self.myargs[0] + class CryptedAttributes(Attributes): defaulttype = 'password'