Skip to content

Latest commit

 

History

History
276 lines (141 loc) · 6.82 KB

hackney_multipart.md

File metadata and controls

276 lines (141 loc) · 6.82 KB

Module hackney_multipart

module to encode/decode multipart.

Data Types


body_cont() = cont(more(body_result()))

body_result() = {body, binary(), body_cont()} | end_of_part()

cont(T) = fun(() -> T)

end_of_part() = {end_of_part, cont(more(part_result()))}

headers() = {headers, http_headers(), body_cont()}

http_headers() = [{binary(), binary()}]

more(T) = T | {more, parser(T)}

parser(T) = fun((binary()) -> T)

part_parser() = parser(more(part_result()))

part_result() = headers() | eof

Function Index

boundary/0
decode_form/2decode a multipart form.
encode_form/1encode a list of parts a multipart form.
encode_form/2
len_mp_stream/2get the size of a mp stream.
mp_data_header/2return the multipart header for a data.
mp_eof/1return the boundary ending a multipart.
mp_file_header/2return the multipart header for a file that will be sent later.
mp_header/2create a generic multipart header.
mp_mixed_header/2return the mixed multipart header.
parser/1Return a multipart parser for the given boundary.
part/3create a part.

Function Details

boundary/0


boundary() -> binary()

decode_form/2


decode_form(Boundary::binary(), Body::binary()) -> {ok, list()} | {error, term()}

decode a multipart form.

encode_form/1

encode_form(Parts) -> any()

encode a list of parts a multipart form. Parts can be under the form:

  • {file, Path} : to send a file

  • {file, Path, ExtraHeaders} : to send a file with extra headers

  • {file, Path, Name, ExtraHeaders}: to send a file with DOM element name and extra headers

  • {mp_mixed, Name, Boundary} to send a mixed multipart.

  • {mp_mixed_eof, Boundary}: to signal the end of the mixed multipart boundary.

  • {Name, Data}: to send a custom content as a part

  • {Name, Data, ExtraHeaders}: the same as above but with extra headers.

encode_form/2


encode_form(Parts::list(), Boundary::binary()) -> {binary(), integer()}

len_mp_stream/2

len_mp_stream(Parts, Boundary) -> any()

get the size of a mp stream. Useful to calculate the content-length of a full multipart stream and send it as an identity transfer-encoding instead of chunked so any server can handle it.

Calculated Parts can be under the form:

  • {file, Path} : to send a file

  • {file, Path, ExtraHeaders} : to send a file with extra headers

  • {file, Path, Name, ExtraHeaders} : to send a file with DOM element name and extra headers

  • {mp_mixed, Name, Boundary} to send a mixed multipart. multipart boundary.

  • {Name, DataLen}: to send a custom content as a part

  • {Name, DataLen, ExtraHeaders}: the same as above but with extra headers.

mp_data_header/2


mp_data_header(X1::{Name::binary(), DataLen::integer()} | {Name::binary(), DataLen::integer(), ExtraHeaders::[{binary(), binary()}]} | {Name::binary(), DataLen::integer(), {Disposition::binary(), Params::[{binary(), binary()}]}, ExtraHeaders::[{binary(), binary()}]}, Boundary::binary()) -> {binary(), DataLen::integer()}

return the multipart header for a data

mp_eof/1

mp_eof(Boundary) -> any()

return the boundary ending a multipart

mp_file_header/2


mp_file_header(X1::{file, Path::binary()} | {file, Path::binary(), ExtraHeaders::[{binary(), binary()}]} | {file, Path::binary(), Name::binary(), ExtraHeaders::[{binary(), binary()}]} | {file, Path::binary(), {Disposition::binary(), Params::[{binary(), binary()}]}, ExtraHeaders::[{binary(), binary()}]}, Boundary::binary()) -> {binary(), FileSize::integer()}

return the multipart header for a file that will be sent later

mp_header/2

mp_header(Headers, Boundary) -> any()

create a generic multipart header

mp_mixed_header/2


mp_mixed_header(X1::{Name::binary(), MixedBoundary::binary()}, Boundary::binary()) -> {binary(), 0}

return the mixed multipart header

parser/1


parser(Boundary::binary()) -> part_parser()

Return a multipart parser for the given boundary.

part/3

part(Content, Headers, Boundary) -> any()

create a part