Function pact_ffi::mock_server::handles::pactffi_with_binary_body

source ·
#[no_mangle]
pub extern "C" fn pactffi_with_binary_body(
    interaction: InteractionHandle,
    part: InteractionPart,
    content_type: *const c_char,
    body: *const u8,
    size: size_t
) -> bool
Expand description

Adds the body for the interaction. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started)

  • part - The part of the interaction to add the body to (Request or Response).
  • content_type - The content type of the body. Defaults to application/octet-stream if it is NULL. Will be ignored if a content type header is already set.
  • body - Body contents as a pointer to a byte array
  • size - Number of bytes in the body

For HTTP and async message interactions, this will overwrite the body. With asynchronous messages, the part parameter will be ignored. With synchronous messages, the request contents will be overwritten, while a new response will be appended to the message.

§Safety

This function is safe to use as long as the following conditions are true: The content type must either be a NULL pointer, or point to valid UTF-8 encoded NULL-terminated string. The body pointer must be valid for reads of size bytes, and it must be properly aligned and consecutive (that just means it must point a continuous array of at least size bytes that can be read in a single operation and not to non-continuous structures like linked lists, etc.).

§Error Handling

If the body is a NULL pointer, it will set the body contents as empty. If the content type is a null pointer, it will set the content type as application/octet-stream. Returns false if the interaction or Pact can’t be modified (i.e. the mock server for it has already started) or an error has occurred.