ReqClient.Channel.Httpc (Ehelper v0.2.8)

View Source

Simple 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

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.

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

check_ssl_config(verify_host \\ true)

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(url, opts \\ [])

delete request

delete!(url, opts \\ [])

direct(url)

ensure_started!(apps \\ [:inets, :ssl])

get(url, opts \\ [])

get request

get!(url, opts \\ [])

get_content_wise_resp_body?(opts \\ [])

get_cookies(profile \\ nil)

Produces a list of the entire cookie database. Intended for debugging/testing purposes. If no profile is specified, the default profile is used.

get_http_opts(items \\ :all, profile \\ nil)

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

get_http_proxy(opts)

get_https_proxy(opts)

get_no_proxy_list()

get_proxy_opts()

get_proxy_opts(opts)

get_req_headers(headers, debug? \\ false)

get_sessions(profile \\ nil)

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_http_opts(opts \\ [])

Get SSL options for httpc requests

  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(url, opts \\ [])

head request

head!(url, opts \\ [])

inets_info()

info(profile \\ nil)

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)

no_proxy_glob_host(host)

post(url, opts \\ [])

post request

post!(url, opts \\ [])

random_profile_name()

Generate a random profile per request to avoid reuse

remove_proxy()

req(uri, opts \\ [])

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_proxy(opts \\ [], debug? \\ false)

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.

smart_ssl_http_opts(arg1, opts)

start_profile!(profile \\ random_profile_name())

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.

stop_profile!(profile)

verbose(mode \\ :verbose)

mode :: false | verbose | debug | trace,