[FFI] with_body
and with_binary_file
confusion
#336
Labels
bug
Indicates an unexpected problem or unintended behavior
with_body
and with_binary_file
confusion
#336
Summary
The FFI provides two functions to set the expected body of an interaction:
with_body(interaction, part, content_type, body)
with_binary_file(interaction, part, content_type, body, size)
Both function require the body to be passed as a
char*
pointer to an array, but they differ in that (at least according to the documentation):with_body
requires the interaction contents to be either a NULL pointer, or point to valid UTF-8 encoded NULL-terminated strings. Otherwise, behaviour is undefined.with_binary_file
requires the interaction contents to be valid for reads of size bytes, and it must be properly aligned and consecutive.Based on the discussion in this Slack thread it would appear that
with_binary_file
can only be used with V3 (or later?) interactions.This leaves unfortunately no way to specify an interaction with an arbitrary binary body for interactions using versions prior to V3 (at least, according to the documentation).
Proposed changes
Alternative 1
A new
with_binary_body
methodTo avoid changing the behaviour of existing functions, the simplest change might just be to add a new
with_binary_body
function for V1 interactions. It would act in a similar way towith_body
, albeit with little/no smarts in parsing the content.Update
with_binary_file
and its documentationThe
with_binary_file
documentation should be updated to make it very clear that this function should not be used for interaction versions prior to V3.Furthermore, I would suggest that the method be updated to do this check programmatically, and return a failure if
with_binary_file
is called with an incompatible version.Alternative 2
Update
with_binary_file
behaviour based on interaction versionInstead of adding a new function, and having
with_binary_file
work only for interactions using v3 or later, the behaviour ofwith_binary_file
could be adjusted based on the interaction version such that:with_binary_file
does not perform intelligent mime-type detections.with_binary_file
keeps its existing behaviour.The text was updated successfully, but these errors were encountered: