HTTPoison.Handlers.Multipart behaviour (HTTPoison v2.2.1) View Source

Provides a set of functions to handle multipart requests/responses

HTTPoison.Handlers.Multipart defines the following list of functions:

# Used to parse a multipart response body
# @type body :: binary | {:form, [{atom, any}]} | {:file, binary}
# @spec decode_body(Response.t()) :: body
# def decode_body(response)

Link to this section Summary


Parses a multipart response body.

Link to this section Types


body() :: binary() | {:form, [{atom(), any()}]} | {:file, binary()}

Link to this section Callbacks


decode_body(HTTPoison.Response.t()) :: body()

Link to this section Functions

Parses a multipart response body.

It uses :hackney_headers to understand if the content type of the response is multipart, in which case it uses :hackney_multipart to decode the body of the response.

For example, if we have the following multipart response body:

Content-type: application/json
{"1": "first"}
Content-type: application/json
{"2": "second"}

We can parse the body of the response to its various parts:

#=> will decode a multipart body, e.g. yielding
# [
#   {[{"Content-Type", "application/json"}], "{"1": "first"}"},
#   {[{"Content-Type", "application/json"}], "{"2": "second"}"}
# ]

In case the content type is not multipart, the original body is returned.