CloakedReq.Request (cloaked_req v0.5.1)

Copy Markdown View Source

Converts a Req.Request into the metadata map and body expected by the Rust NIF.

Validates and normalizes all adapter options (impersonate, timeouts, proxy, body size, TLS verification). The metadata map is passed to CloakedReq.Native; the body is passed as a raw binary.

Summary

Functions

Normalizes a positive-integer connect timeout in milliseconds.

Normalizes an :impersonate profile option to the string the NIF expects.

Normalizes the :insecure_skip_verify option to a boolean.

Builds a native payload tuple from a Req.Request.

Functions

normalize_connect_timeout(value, field \\ "connect_options timeout")

@spec normalize_connect_timeout(term(), String.t()) ::
  {:ok, pos_integer()} | {:error, CloakedReq.Error.t()}

Normalizes a positive-integer connect timeout in milliseconds.

Shared by the request bridge and CloakedReq.Pool; field names the option in the error message so each caller reports its own option name.

normalize_impersonate(value)

@spec normalize_impersonate(term()) ::
  {:ok, nil | String.t()} | {:error, CloakedReq.Error.t()}

Normalizes an :impersonate profile option to the string the NIF expects.

Shared by the request bridge and CloakedReq.Pool. Returns {:ok, nil} for no profile, {:ok, name} for a profile atom, or an :invalid_request error.

normalize_insecure_skip_verify(value)

@spec normalize_insecure_skip_verify(term()) ::
  {:ok, boolean()} | {:error, CloakedReq.Error.t()}

Normalizes the :insecure_skip_verify option to a boolean.

Shared by the request bridge and CloakedReq.Pool. Returns {:ok, boolean} or an :invalid_request error.

to_native_payload(request)

@spec to_native_payload(Req.Request.t()) ::
  {:ok, {map(), binary() | nil}} | {:error, CloakedReq.Error.t()}

Builds a native payload tuple from a Req.Request.

Validates the request (URL scheme, body encoding, adapter options) and returns {:ok, {metadata_map, body_binary}} or {:error, %CloakedReq.Error{}}.