locus_http_download (locus v2.3.15)

Copy Markdown View Source

Downloads a file using HTTP(S) without blocking the caller.

Summary

Types

body()

-type body() :: binary().

event()

event_download_dismissed()

-type event_download_dismissed() :: {download_dismissed, full_http_response()}.

event_download_failed_to_start()

-type event_download_failed_to_start() ::
          {download_failed_to_start, reason_for_download_failing_to_start()}.

event_download_finished()

-type event_download_finished() ::
          {download_finished, BodySize :: non_neg_integer(), {ok, TrailingHeaders :: headers()}} |
          {download_finished, BodySize :: non_neg_integer(), {error, term()}} |
          {download_finished, BodySize :: non_neg_integer(), {error, timeout}}.

event_download_redirected()

-type event_download_redirected() :: {download_redirected, redirection()}.

event_download_started()

-type event_download_started() :: {download_started, headers()}.

event_request_sent()

-type event_request_sent() :: {request_sent, url(), headers()}.

full_http_response()

-type full_http_response() :: {http, response_status(), headers(), body()}.

headers()

-type headers() :: [{string(), string()}].

msg()

-type msg() ::
          {event, event()} |
          {finished, {success, success()}} |
          {finished, dismissed} |
          {finished, {error, term()}}.

opt()

-type opt() ::
          {connect_timeout, timeout()} |
          {download_start_timeout, timeout()} |
          {idle_download_timeout, timeout()} |
          insecure |
          {insecure, boolean()} |
          {censor_query, CensoredKeys :: [atom()]}.

reason_for_download_failing_to_start()

-type reason_for_download_failing_to_start() ::
          full_http_response() |
          too_many_redirections |
          {invalid_redirection, term()} |
          {error, term()} |
          timeout.

redirection()

-type redirection() :: #{url := url(), permanence := permanent | temporary}.

response_status()

-type response_status() :: {100..999, binary()}.

state()

-opaque state()

success()

-type success() :: #{headers := headers(), body := binary()}.

url()

-type url() :: string().

Functions

code_change/3

-spec code_change(term(), state(), term()) -> {ok, state()}.

handle_call(Call, From, State)

-spec handle_call(term(), {pid(), reference()}, state()) -> {stop, unexpected_call, state()}.

handle_cast(Cast, State)

-spec handle_cast(term(), state()) -> {stop, unexpected_cast, state()}.

handle_info/2

-spec handle_info(term(), state()) ->
                     {noreply, state()} | {stop, normal, state()} | {stop, unexpected_info, state()}.

init/1

-spec init([InitArg, ...]) -> {ok, state()}
              when
                  InitArg :: OwnerPid | URL | Headers | Opts,
                  OwnerPid :: pid(),
                  URL :: url(),
                  Headers :: headers(),
                  Opts :: [opt()].

start_link(URL, Headers, Opts)

-spec start_link(url(), headers(), [opt()]) -> {ok, pid()}.

terminate(Reason, State)

-spec terminate(term(), state()) -> ok.

validate_opts(MixedOpts)

-spec validate_opts(proplists:proplist()) ->
                       {ok, {[opt()], proplists:proplist()}} | {error, BadOpt :: term()}.