View Source K8s.Client.Mint.HTTPAdapter (k8s v2.4.2)
The Mint client implementation. This module handles both, HTTP requests and websocket connections.
Processes
The module creates a process per connection to the Kubernetes API server.
It supports HTTP/2
for HTTP requests, but not for websockets. So while
an open connection can process multiple requests (if the server supports
HTTP/2
), it can only process one single websocket connection.
Therefore, each websocket connection is handled in its own process.
State
The module keeps track of the Mint.HTTP
connection struct and a map of
pending requests (K8s.Client.Mint.Request
) for that connection, indexed by the
Mint.Types.request_ref()
.
Requests
Requests are calls to the GenServer that immediately return while the GenServer
receives the response parts in the background. The way these response parts are
returned depends on the state_to
argument passed to request/7
resp.
websocket_request/5
. See these function's docs for more details.
Summary
Functions
Returns a specification to start this module under a supervisor.
Returns connection arguments for the given URI
and HTTP options.
Returns response parts / frames that were buffered by the process. The
stream_to
must have been set to nil
in request/7
or
websocket_request/5
.
Starts a HTTP request. The way the response parts are returned depends on the
stream_to
argument passed to it.
Opens a connection to Kubernetes, defined by uri
and opts
,
and starts the GenServer.
Upgrades to a Websocket connection. The way the frames are returned depends
on the stream_to
argument passed to it.
Sends the given data
throught the websocket specified by the request_ref
.
Types
@type t() :: %K8s.Client.Mint.HTTPAdapter{ conn: Mint.HTTP.t(), requests: %{required(reference()) => K8s.Client.Mint.Request.t()} }
Describes the state of the connection.
:conn
- The current state of theMint
connection.:requests
- The opened requests over this connection (OnlyHTTP/2
connections will hold multiple entries in this field.)
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec connection_args( URI.t(), keyword() ) :: connection_args_t()
Returns connection arguments for the given URI
and HTTP options.
@spec open?(GenServer.server(), :read | :write | :read_write) :: boolean()
@spec recv(GenServer.server(), reference()) :: list()
Returns response parts / frames that were buffered by the process. The
stream_to
must have been set to nil
in request/7
or
websocket_request/5
.
If the buffer is empty, this call blocks until the next response part / frame is received.
@spec request( GenServer.server(), method :: binary(), path :: binary(), Mint.Types.headers(), body :: iodata() | nil | :stream, pool :: pid() | nil, stream_to :: pid() | nil ) :: {:ok, reference()} | {:error, K8s.Client.HTTPError.t()}
Starts a HTTP request. The way the response parts are returned depends on the
stream_to
argument passed to it.
nil
- response parts are buffered. In order to receive them, the caller needs torecv/2
passing it therequest_ref
returned by this function.pid
- response parts are sent to the process with the givenpid
.{pid, reference}
- response parts are sent to the process with the givenpid
. Messages are of the form{reference, response_part}
.
@spec start_link(connection_args_t()) :: GenServer.on_start()
Opens a connection to Kubernetes, defined by uri
and opts
,
and starts the GenServer.
@spec websocket_request( pid(), path :: binary(), Mint.Types.headers(), pool :: pid() | nil, stream_to :: pid() | nil ) :: {:ok, reference()} | {:error, K8s.Client.HTTPError.t()}
Upgrades to a Websocket connection. The way the frames are returned depends
on the stream_to
argument passed to it.
nil
- frames are buffered. In order to receive them, the caller needs torecv/2
passing it therequest_ref
returned by this function.pid
- frames are sent to the process with the givenpid
.{pid, reference}
- frames are sent to the process with the givenpid
. Messages are of the form{reference, response_part}
.
@spec websocket_send( GenServer.server(), reference(), term() ) :: :ok
Sends the given data
throught the websocket specified by the request_ref
.