Roundup Tracker - Issues

Issue 2551289

classification
Invalid REST Accept header with post/put performs change before returning 406.
Type: behavior Severity: normal
Components: API Versions:
process
Status: fixed fixed
:
: rouilj : rouilj
Priority: :

Created on 2023-08-02 21:58 by rouilj, last changed 2024-12-08 07:16 by rouilj.

Messages
msg7822 Author: [hidden] (rouilj) Date: 2023-08-02 21:58
Sending a POST, PUT (maybe PATCH) with an accept header that is not
application/json or xml (if enabled) will complete the request before throwing
a 406 error.

This is incorrect. The Accept header should be validated first and a 406 returned
before any change/work is done.

Note that the property binary_content should allow a value other than json and xml.
In this case, the Accept value must match the mime type of the file content (as reported in 
the file metadata at data/file/N data.attributes.type). The response will be the raw binary
file with the Content-Type set to the mime type and the content-length the length of the
binary content.

This also applies to a GET, but a GET is read only so less of an issue.

This is a prereq for issue 2551068.
msg8211 Author: [hidden] (rouilj) Date: 2024-12-08 07:16
Fixed in changeset:   8177:2967f37e73e4 as part of refactoring work on 
RestfulInstance::dispatch().

Created a new method: determine_output_format(self, uri) that return a tuple:

  mime_type - None if no matching type found otherwise 'json' or 'xml' for now
  url - modified url to be dispatched if mime type found with '.json' or '.xml' suffix in url
  error - an error object, None if no error found.

If mime_type is None, error is not None and vice versa.

mime_type is a bit of a misnomer. the abbreviated xml and json types are used for
regular rest output because they are short. But for supporting binary_content a
full mime type can be assigned without issue. 

Passed in CI with 97% coverage for the patch. I don't test xml output and
the patch changed that code path.
History
Date User Action Args
2024-12-08 07:16:20rouiljsetstatus: new -> fixed
assignee: rouilj
resolution: fixed
messages: + msg8211
2023-08-02 21:58:25rouiljcreate