vpndetection_http (vpndetection v3.3.2)
View SourceThe transport: one httpc profile, retry policy, and response classification.
A request either buffers its body or streams it into a SINK. A lookup and a database listing are small enough to hold; a dataset file is not, and the catalog runs to gigabytes, so the sink is a fold that never sees more than one chunk at a time.
Summary
Functions
Start what the default transport needs.
Fetch and decode a JSON body, retrying what is worth retrying.
Fetch the Location of a redirect without following it.
Stream one absolute URL through Sink, answering what it wrote.
The default transport, closing over nothing.
Send one OAuth request, attempted again up to Retries times. A 2xx goes to Decode with its status; a 4xx naming an RFC 6749 error is that refusal, which is never retryable; anything else is the ordinary error for its status.
A request to the authorization server, carrying NO credential whatever the client holds: these endpoints have no use for the API key, and on the token endpoint an authorization header reads as client authentication. A form is POSTed, its type riding as the content-type header whole/1 hands to httpc.
POST a JSON body and decode the JSON object it answers with. The one request with a body: the batch.
Types
-type result() :: #{headers := [{binary(), binary()}], status => 100..599, body => binary(), written => non_neg_integer(), acc => term()}.
Functions
-spec ensure_ready() -> ok.
Start what the default transport needs.
-spec get_json(map(), binary(), [{binary(), binary()}], non_neg_integer()) -> {ok, map()} | {error, vpndetection_error:error()}.
Fetch and decode a JSON body, retrying what is worth retrying.
-spec get_redirect(map(), binary(), [{binary(), binary()}], non_neg_integer()) -> {ok, binary()} | {error, vpndetection_error:error()}.
Fetch the Location of a redirect without following it.
-spec get_stream(map(), binary(), sink(), non_neg_integer()) -> {ok, #{written := non_neg_integer(), acc := term()}} | {error, vpndetection_error:error()}.
Stream one absolute URL through Sink, answering what it wrote.
No credential is attached. This is only ever pointed at the presigned link the download endpoint hands out, which authorizes itself, and forwarding the API key would hand it to a host with no business holding it.
-spec httpc_fun() -> http_fun().
The default transport, closing over nothing.
-spec oauth(map(), request(), non_neg_integer(), fun((100..599, binary()) -> {ok, term()} | {error, vpndetection_error:error()})) -> {ok, term()} | {error, vpndetection_error:error()}.
Send one OAuth request, attempted again up to Retries times. A 2xx goes to Decode with its status; a 4xx naming an RFC 6749 error is that refusal, which is never retryable; anything else is the ordinary error for its status.
A request to the authorization server, carrying NO credential whatever the client holds: these endpoints have no use for the API key, and on the token endpoint an authorization header reads as client authentication. A form is POSTed, its type riding as the content-type header whole/1 hands to httpc.
-spec post_json(map(), binary(), binary(), non_neg_integer()) -> {ok, map()} | {error, vpndetection_error:error()}.
POST a JSON body and decode the JSON object it answers with. The one request with a body: the batch.