Skip to content

Commit

Permalink
Fix doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ferraz-oliveira committed Dec 19, 2020
1 parent 4238310 commit f8966d2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 64 deletions.
26 changes: 14 additions & 12 deletions src/hackney.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,19 @@ cancel_request(Ref) ->

%% @doc set client options.
%% Options are:
%% - `async': to fetch the response asynchronously
%% - `{async, once}': to receive the response asynchronously one time.
%% To receive the next message use the function `hackney:stream_next/1'.
%% - `{stream_to, pid()}': to set the pid where the messages of an
%% asynchronous response will be sent.
%% - `{follow_redirect, bool()}' : if true a redirection will be
%% followed when the response is received synchronously
%% - `{force_redirect, bool()}' : if true a 301/302 redirection will be
%% followed even on POST.
%% - `{max_redirect, integer()}' the maximum number of redirections that
%% will be followed
%% <ul>
%% <li>`async': to fetch the response asynchronously</li>
%% <li>`{async, once}': to receive the response asynchronously one time.
%% To receive the next message use the function `hackney:stream_next/1'.</li>
%% <li>`{stream_to, pid()}': to set the pid where the messages of an
%% asynchronous response will be sent.</li>
%% <li>`{follow_redirect, bool()}' : if true a redirection will be
%% followed when the response is received synchronously</li>
%% <li>`{force_redirect, bool()}' : if true a 301/302 redirection will be
%% followed even on POST.</li>
%% <li>`{max_redirect, integer()}' the maximum number of redirections that
%% will be followed</li>
%% </ul>
-spec setopts(client_ref(), list()) -> ok.
setopts(Ref, Options) ->
hackney_manager:get_state(Ref, fun(State) ->
Expand Down Expand Up @@ -419,7 +421,7 @@ finish_send_body(Ref) ->
%% <li>`{part, Name}': to start sending a part without length in a streaming
%% fashion</li>
%% <li>`{part, Name, ExtraHeader}': to start sending a part without
%% lengthin a streaming fashion</li>
%% length in a streaming fashion</li>
%% <li>`{part_bin, Bin}': To send part of part</li>
%% <li>`{part, eof}': To notify the end of the part </li>
%% <li>`{mp_mixed, Name, MixedBoundary}': To notify we start a part with a a mixed
Expand Down
71 changes: 37 additions & 34 deletions src/hackney_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,33 @@
%%% you can process later with `hackney_http:execute/2' when
%%% `{more, ...}' is returnned or `hackney_http:execute/1' in other
%%% cases:
%%%
%%% - `{response, http_version(), status(), http_reason(), parser()}':
%%% when the first line of a response is parsed
%%% - `{request, http_version(), http_method(), uri(), parser()}':
%%% when the first line of a request (on servers) is parsed
%%% - `{more, parser()}': when the parser need more
%%% <ul>
%%% <li>`{response, http_version(), status(), http_reason(), parser()}':
%%% when the first line of a response is parsed</li>
%%% <li>`{request, http_version(), http_method(), uri(), parser()}':
%%% when the first line of a request (on servers) is parsed</li>
%%% <li>`{more, parser()}': when the parser need more
%%% data. The new data should be passed to `hackney_http:execute/2' with
%%% the new parser() state received.
%%% - `{header, {Name :: binary(), Value :: binary()}, parser()}':
%%% the new parser() state received.</li>
%%% <li>`{header, {Name :: binary(), Value :: binary()}, parser()}':
%%% when an header has been parsed. To continue the parsing you must
%%% call the given `parser()' with `hackney_http:execute/1'.
%%% - `{headers_complete, parser()}' : when all headers have been parsed.
%%% call the given `parser()' with `hackney_http:execute/1'.</li>
%%% <li>`{headers_complete, parser()}' : when all headers have been parsed.
%%% To continue the parsing you must call the given `parser()' state
%%% with `hackney_http:execute/1'.
%%% - `{more, parser(), binary()}': on body, when
%%% with `hackney_http:execute/1'.</li>
%%% <li>`{more, parser(), binary()}': on body, when
%%% the parser need more data. The new data should be passed to
%%% `hackney_http:execute/2' (with `parser()' ) when received. The binary at the end of the
%%% tuple correspond to the actual buffer of the parser. It may be used
%%% for other purpose, like start to parse a new request on pipeline
%%% connections, for a proxy...
%%% - `{ok, binary(), parser()}': on body, when a chunk has been
%%% connections, for a proxy...</li>
%%% <li>`{ok, binary(), parser()}': on body, when a chunk has been
%%% parsed. To continue the parsing you must call
%%% `hackney_http:execute/1' with the given `parser()'.
%%% - `{done, binary()}': when the parsing is done. The binary
%%% given correpond to the non parsed part of the internal buffer.
%%% - `{error, term{}}': when an error happen
%%% `hackney_http:execute/1' with the given `parser()'.</li>
%%% <li>`{done, binary()}': when the parsing is done. The binary
%%% given correpond to the non parsed part of the internal buffer.</li>
%%% <li>`{error, term{}}': when an error happen</li>
%%% </ul>

-module(hackney_http).

Expand Down Expand Up @@ -102,29 +103,31 @@ parser() ->
%%
%% Available options:
%% <ul>
%% <li>`auto' : autodetect if the binary parsed is a response or a
%% request (default).</li>
%% <li>`response': set the parser to parse a response</li>
%% <li>`request': set the parser to parse a request (server)</li>
%% <li>`{max_line_lenght, Max}': set the maximum size of a line parsed
%% before we give up.</li>
%% <li>`{max_lines_empty, Max}': the maximum number of empty line we
%% accept before the first line happen</li>
%% <li>`auto' : autodetect if the binary parsed is a response or a
%% request (default).</li>
%% <li>`response': set the parser to parse a response</li>
%% <li>`request': set the parser to parse a request (server)</li>
%% <li>`{max_line_lenght, Max}': set the maximum size of a line parsed
%% before we give up.</li>
%% <li>`{max_lines_empty, Max}': the maximum number of empty line we
%% accept before the first line happen</li>
%% </ul>
-spec parser(parser_options()) -> parser().
parser(Options) ->
parse_options(Options, #hparser{}).

%% @doc retrieve a parser property.
%% Properties are:
%% - `buffer': internal buffer of the parser (non parsed)
%% - `state': the current state (on_status, on_header, on_body, done)
%% - `version': HTTP version
%% - `content_length': content length header if any
%% - `transfer_encoding': transfer encoding header if any
%% - `content_type': content type header if any
%% - `location': location header if any
%% - `connection': connection header if any.
%% <ul>
%% <li>`buffer': internal buffer of the parser (non parsed)</li>
%% <li>`state': the current state (on_status, on_header, on_body, done)</li>
%% <li>`version': HTTP version</li>
%% <li>`content_length': content length header if any</li>
%% <li>`transfer_encoding': transfer encoding header if any</li>
%% <li>`content_type': content type header if any</li>
%% <li>`location': location header if any</li>
%% <li>`connection': connection header if any.</li>
%% </ul>
-spec get(parser(), atom() | [atom()]) -> any().
get(Parser, Props) when is_list(Props) ->
[get_property(P, Parser) || P <- Props];
Expand Down
40 changes: 22 additions & 18 deletions src/hackney_multipart.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@

%% @doc 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.
%% <ul>
%% <li>`{file, Path}' : to send a file</li>
%% <li>`{file, Path, ExtraHeaders}' : to send a file with extra headers</li>
%% <li>`{file, Path, Name, ExtraHeaders}': to send a file with DOM element name and extra headers</li>
%% <li>`{mp_mixed, Name, Boundary}' to send a mixed multipart.</li>
%% <li>`{mp_mixed_eof, Boundary}': to signal the end of the mixed
%% multipart boundary.</li>
%% <li>`{Name, Data}': to send a custom content as a part</li>
%% <li>`{Name, Data, ExtraHeaders}': the same as above but with extra
%% headers.</li>
%% </ul>
encode_form(Parts) ->
encode_form(Parts, boundary()).

Expand Down Expand Up @@ -141,7 +143,7 @@ mp_header(Headers, Boundary) ->
BinHeaders = hackney_headers:to_binary(Headers),
<<"--", Boundary/binary, "\r\n", BinHeaders/binary >>.

%% @doc return the boundary ennding a multipart
%% @doc return the boundary ending a multipart
mp_eof(Boundary) ->
<<"--", Boundary/binary, "--\r\n">>.

Expand All @@ -156,14 +158,16 @@ part(Content, Headers, Boundary) ->
%% 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.
%% <ul>
%% <li>`{file, Path}' : to send a file</li>
%% <li>`{file, Path, ExtraHeaders}' : to send a file with extra headers</li>
%% <li>`{file, Path, Name, ExtraHeaders}' : to send a file with DOM element name and extra headers</li>
%% <li>`{mp_mixed, Name, Boundary}' to send a mixed multipart.
%% multipart boundary.</li>
%% <li>`{Name, DataLen}': to send a custom content as a part</li>
%% <li>`{Name, DataLen, ExtraHeaders}': the same as above but with extra
%% headers.</li>
%% </ul>
len_mp_stream(Parts, Boundary) ->
Size = lists:foldl(fun
({file, Path}, AccSize) ->
Expand Down

0 comments on commit f8966d2

Please sign in to comment.