Dowser. Client. HTTP. Profile
(Dowser.Client v0.3.0)
View Source
Manages the :httpc profiles Dowser.Client.HTTP sends requests through.
A profile is an isolated :httpc manager with its own connection pool,
session settings and cookie store. dowser_client never uses :httpc's
shared :default profile unless asked to, so its settings — and its
keep-alive sessions — are never shared with the rest of the application.
Profiles are started on demand, the first time a request needs one, and
configured once with :httpc.set_options/2. Give each cluster its own
profile when they should not share a connection pool:
config :dowser_client,
contexts: [
default: [endpoint: "https://search.internal:9200", profile: :search],
logs: [endpoint: "https://logs.internal:9200", profile: :logs]
]Options
:profile_opts (on a context, globally, or per request) is passed to
:httpc.set_options/2. dowser_client's defaults, tuned for a search
cluster rather than a browser:
max_sessions: 20— concurrent keep-alive connections per host/port (:httpc's own default is 2, far too few for a search backend).max_keep_alive_length: 100— requests queued on one session.keep_alive_timeout: 120_000— how long an idle session is kept.cookies: :disabled— a search API has no use for a cookie store.
Anything :httpc.set_options/2 accepts can be set: :pipeline_timeout,
:max_pipeline_length, :proxy, :https_proxy, :ipfamily,
:socket_opts, :verbose, :unix_socket, ...
config :dowser_client, profile_opts: [max_sessions: 50, pipeline_timeout: 5_000]Because options are applied when the profile starts, changing them later has
no effect until reset/2 re-applies them.
Summary
Functions
The profile used when none is configured.
The :httpc.set_options/2 defaults applied to every profile.
Ensures name is started and configured, returning {:ok, name}.
Reports :httpc's own view of name — its open sessions, queued requests
and current options. Handy for checking that keep-alive is doing what you
expect.
Forgets that name was started, so the next request starts and configures it
again. Does not stop the profile.
Re-applies opts to name, starting it if needed.
Types
@type t() :: atom()
Functions
@spec default() :: t()
The profile used when none is configured.
@spec default_opts() :: keyword()
The :httpc.set_options/2 defaults applied to every profile.
Ensures name is started and configured, returning {:ok, name}.
Idempotent and cheap after the first call: the outcome is memoized in
:persistent_term, so a steady-state request only reads a term.
Reports :httpc's own view of name — its open sessions, queued requests
and current options. Handy for checking that keep-alive is doing what you
expect.
@spec invalidate(t()) :: :ok
Forgets that name was started, so the next request starts and configures it
again. Does not stop the profile.
Re-applies opts to name, starting it if needed.
Use it when profile options change at runtime — ensure_started/2 only
applies them once.