ReqClient.Channel.Httpc (Ehelper v0.2.8)
View SourceSimple http/1 Client by wrapping :httpc (erlang builtin HTTP/1.1 client)
NOTE: please keep this file standalone, so it can be used in archives like ehelper!!!
- DONOT depends on non-elixir builtin modules
Example
eg. Hc.get "https://slink.fly.dev/api/ping"
todo
- improve to use standalone profile for proxy and custom options
Options
ssl_kind: :none | :peer debug: true|false timeout: in ms or :infinite body_format: :binary # :binary or :string other https://www.erlang.org/doc/apps/inets/httpc.html#request/5
Links
- https://www.erlang.org/doc/apps/inets/httpc.html from inets app
- more ref notes/httpc.md
Summary
Functions
ssl - This is the SSL/TLS connecting configuration option. Default value is obtained by calling httpc:ssl_verify_host_options(true). See ssl:connect/2,3,4 for available options.
delete request
get request
Produces a list of the entire cookie database. Intended for debugging/testing purposes. If no profile is specified, the default profile is used.
Get httpc options
This function is intended for debugging only. It produces a slightly processed dump of the session database. The first list of the session information tuple will contain session information on an internal format. The last two lists of the session information tuple should always be empty if the code is working as intended. If no profile is specified, the default profile is used.
Get SSL options for httpc requests
head request
Produces a list of miscellaneous information. Intended for debugging. If no profile is specified, the default profile is used.
post request
Generate a random profile per request to avoid reuse
Base request method
Set httpc proxy from system env
When starting the Inets application, a manager process for the default profile is started. The functions in this API that do not explicitly use a profile accesses the default profile.
mode :: false | verbose | debug | trace,
Functions
ssl - This is the SSL/TLS connecting configuration option. Default value is obtained by calling httpc:ssl_verify_host_options(true). See ssl:connect/2,3,4 for available options.
iex(19) > :httpc.ssl_verify_host_options(true) |> Keyword.keys() [:verify, :cacerts, :customize_hostname_check]
iex(21)> ReqClient.Channel.Httpc.check_ssl_config(true) true iex(25)> ReqClient.Channel.Httpc.check_ssl_config(false) false
delete request
get request
Produces a list of the entire cookie database. Intended for debugging/testing purposes. If no profile is specified, the default profile is used.
Get httpc options
OptionItem :: proxy | https_proxy | max_sessions | keep_alive_timeout | max_keep_alive_length | pipeline_timeout | max_pipeline_length | cookies | ipfamily | ip | port | socket_opts | verbose | unix_socket
This function is intended for debugging only. It produces a slightly processed dump of the session database. The first list of the session information tuple will contain session information on an internal format. The last two lists of the session information tuple should always be empty if the code is working as intended. If no profile is specified, the default profile is used.
Get SSL options for httpc requests
- https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/inets
- https://security.erlef.org/secure_coding_and_deployment_hardening/ssl
- https://www.erlang.org/doc/apps/ssl/ssl.html#t:client_option_cert/0
ssl:connect("example.net", 443, [
{verify, verify_peer},
{cacerts, public_key:cacerts_get()},
{depth, 3},
{customize_hostname_check, [
{match_fun, public_key:pkix_verify_hostname_match_fun(https)}
]}
]).
head request
Produces a list of miscellaneous information. Intended for debugging. If no profile is specified, the default profile is used.
iex> ReqClient.Channel.Httpc.info() iex> ReqClient.Channel.Httpc.info(:manager) iex> ReqClient.Channel.Httpc.info(:hex)
post request
Generate a random profile per request to avoid reuse
Base request method
Options
- debug
- method
- headers %{"header_name1" => ["value1"]}
- body in string
timing
- other channel-specific options
About response
- is map todo typespec
- body: should be binary
- headers: %{"header_name1" => ["value1"]}
- header name should in lowercase string
- value in a list
Set httpc proxy from system env
A profile keeps track of proxy options, cookies, and other options that can be applied to more than one request.
{:proxy, {Proxy :: {HostName, Port}, NoProxy :: [DomainDesc | HostName | IpAddressDesc],}}
HostName - Example: "localhost" or "foo.bar.se"
DomainDesc - Example "*.Domain" or "*.ericsson.se"
IpAddressDesc - Example: "134.138" or "[FEDC:BA98" (all IP addresses starting with 134.138 or FEDC:BA98), "66.35.250.150" or "[2010:836B:4179::836B:4179]" (a complete IP address). proxy defaults to {undefined, []}, that is, no proxy is configured and https_proxy defaults to the value of proxy.
When starting the Inets application, a manager process for the default profile is started. The functions in this API that do not explicitly use a profile accesses the default profile.
mode :: false | verbose | debug | trace,