IMDS.HTTP (imds v1.0.0)

Copy Markdown

The transport every provider uses, built on Req.

A request returns a plain map instead of a raise, so the providers can judge the status code themselves. A connection failure gives the reason of the socket error, for example :econnrefused, :nxdomain or :timeout.

Tests replace the network with Req.Test. Pass the Req options through the :req_options option, for example req_options: [plug: {Req.Test, IMDS}].

Summary

Functions

Return the value of the first header with name.

Send one request and return the status, the headers and the body.

Types

headers()

@type headers() :: [{binary(), binary()}]

method()

@type method() :: :get | :put

response()

@type response() :: %{status: non_neg_integer(), headers: headers(), body: binary()}

Functions

header(resp, name)

@spec header(response(), binary()) :: binary() | nil

Return the value of the first header with name.

The comparison ignores the case of the name. A response header name is compared without case because HTTP does not keep the case of a name.

request(method, url, headers, opts)

@spec request(method(), binary(), headers(), keyword()) ::
  {:ok, response()} | {:error, term()}

Send one request and return the status, the headers and the body.

The :timeout option bounds the connection and the response in milliseconds. The :req_options option adds Req options with Req.merge/2, so its headers are added to the provider headers.