View Source K8s.Client.Mint.HTTPAdapter (k8s v2.5.0)

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

Types

t()

Describes the state of the connection.

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 connection_args_t() ::
  {scheme :: atom(), host :: binary(), port :: integer(), opts :: keyword()}
@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 the Mint connection.
  • :requests - The opened requests over this connection (Only HTTP/2 connections will hold multiple entries in this field.)

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

connection_args(uri, opts)

View Source
@spec connection_args(
  URI.t(),
  keyword()
) :: connection_args_t()

Returns connection arguments for the given URI and HTTP options.

Link to this function

open?(pid, type \\ :read_write)

View Source
@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.

Link to this function

request(pid, method, path, headers, body, pool, stream_to)

View Source
@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 to recv/2 passing it the request_ref returned by this function.
  • pid - response parts are sent to the process with the given pid.
  • {pid, reference} - response parts are sent to the process with the given pid. 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.

Link to this function

websocket_request(pid, path, headers, pool, stream_to)

View Source
@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 to recv/2 passing it the request_ref returned by this function.
  • pid - frames are sent to the process with the given pid.
  • {pid, reference} - frames are sent to the process with the given pid. Messages are of the form {reference, response_part}.
Link to this function

websocket_send(pid, request_ref, data)

View Source
@spec websocket_send(
  GenServer.server(),
  reference(),
  term()
) :: :ok

Sends the given data throught the websocket specified by the request_ref.