Roundup Tracker - Issues

Message8212

Author rouilj
Recipients rouilj, schlatterbeck
Date 2024-12-08.07:18:00
Message-id <1733642280.2.0.790531767091.issue2551068@roundup.psfhosted.org>
In-reply-to
A new method determine_output_format(self, uri) was added in issue 2551289 to refactor
the dispatch method.

One thought could be to modify determine_output_format() to check for a trailing
'binary_content' element in the path. For example:

   curl -X GET -u admin -H "Accept: image/png" -H "X-Requested-With: rest" \
       https://example.com/tracker/rest/data/file/54/binary_content

results in:

  self.client.request.path '/tracker/rest/data/file/54/binary_content'

Parsing the path and splitting the designator allows getting the mime type of the file
via self.client.db.file.get('54', 'type') -> 'image/png'

This can be compared to the Accept header in the `for part in accept_header:`
loop by adding:

  if part[0] == file_type:
     accept_type = file_type

this should result in a call to get_attribute(self, class_name, item_id, attr_name, input)
which returns the binary data in a dict. Which then calls format_dispatch_output().

Then changing format_dispatch_output(self, accept_mime_type, output, pretty_print)
to add the right content type header and return the output['data']['data'] element
if the accept_mime_type is defined. (Note: accept_mime_type should never be
undefined/None with the change to fix issue 2551289.)

Also in the debugger using open('file', 'wb').write(output['data']['data'] wrote
my test png file just fine. Just need to make sure I can write raw binary data to
the http socket.
History
Date User Action Args
2024-12-08 07:18:00rouiljsetmessageid: <1733642280.2.0.790531767091.issue2551068@roundup.psfhosted.org>
2024-12-08 07:18:00rouiljsetrecipients: + rouilj, schlatterbeck
2024-12-08 07:18:00rouiljlinkissue2551068 messages
2024-12-08 07:18:00rouiljcreate