module

Ktistec::Network

Utilities for network operations.

Constants

CONNECT_TIMEOUT = 5.seconds
DNS_TIMEOUT = 5.seconds
Log = ::Log.for(self)
MAX_DISCOVERY_RESPONSE_BYTES = 65536
MAX_GET_RESPONSE_BYTES = 1048576
MAX_POST_RESPONSE_BYTES = 4096
READ_TIMEOUT = 5.seconds
WRITE_TIMEOUT = 5.seconds

Instance methods

get(key_pair, url, headers = HTTP::Headers.new, attempts = 10, *, max_bytes : Int32 = MAX_GET_RESPONSE_BYTES, deadline : Time::Instant | Nil = nil) : Response

Fetches the specified URL via HTTP GET.

When key_pair is supplied, the request is signed; pass nil (or use the no-key-pair overload) for unsigned requests.

Will automatically follow attempts redirects (default 10).

The response body is capped at max_bytes; responses whose Content-Length exceeds the cap are rejected before any body bytes are read, and streamed bodies are aborted if they grow past the cap.

When deadline is supplied, every blocking operation is bounded by the time remaining, and DeadlineExceeded is raised -- before any I/O -- once it is spent.

Source
get(key_pair, url, headers = HTTP::Headers.new, attempts = 10, *, max_bytes : Int32 = MAX_GET_RESPONSE_BYTES, deadline : Time::Instant | Nil = nil, &)

Reads up to max bytes from io into a String. Raises if io has more bytes available past the limit.

Rechecks deadline between reads.

Source
get(url : String | URI, headers = HTTP::Headers.new, attempts = 10, *, max_bytes : Int32 = MAX_GET_RESPONSE_BYTES, deadline : Time::Instant | Nil = nil) : Response

Reads up to max bytes from io into a String. Raises if io has more bytes available past the limit.

Rechecks deadline between reads.

Source
get(url : String | URI, headers = HTTP::Headers.new, attempts = 10, *, max_bytes : Int32 = MAX_GET_RESPONSE_BYTES, deadline : Time::Instant | Nil = nil, &)

Reads up to max bytes from io into a String. Raises if io has more bytes available past the limit.

Rechecks deadline between reads.

Source
get?(key_pair, url, headers = HTTP::Headers.new, attempts = 10, *, max_bytes : Int32 = MAX_GET_RESPONSE_BYTES, deadline : Time::Instant | Nil = nil) : Response | Nil

Reads up to max bytes from io into a String. Raises if io has more bytes available past the limit.

Rechecks deadline between reads.

Source
get?(key_pair, url, headers = HTTP::Headers.new, attempts = 10, *, max_bytes : Int32 = MAX_GET_RESPONSE_BYTES, deadline : Time::Instant | Nil = nil, &)

Reads up to max bytes from io into a String. Raises if io has more bytes available past the limit.

Rechecks deadline between reads.

Source
get?(url : String | URI, headers = HTTP::Headers.new, attempts = 10, *, max_bytes : Int32 = MAX_GET_RESPONSE_BYTES, deadline : Time::Instant | Nil = nil) : Response | Nil

Reads up to max bytes from io into a String. Raises if io has more bytes available past the limit.

Rechecks deadline between reads.

Source
get?(url : String | URI, headers = HTTP::Headers.new, attempts = 10, *, max_bytes : Int32 = MAX_GET_RESPONSE_BYTES, deadline : Time::Instant | Nil = nil, &)

Reads up to max bytes from io into a String. Raises if io has more bytes available past the limit.

Rechecks deadline between reads.

Source
post(key_pair, url : String, body : String, content_type : String, headers = HTTP::Headers.new) : HTTP::Client::Response

Sends a HTTP POST to the specified URL.

Signs the request internally with key_pair.

The returned response carries up to MAX_POST_RESPONSE_BYTES of the response body.

Does not follow redirects.

Source
safe_for_untrusted_outbound_http?(addr : Socket::IPAddress) : Bool

Returns true if addr is a destination Ktistec is willing to send outbound HTTP to on behalf of untrusted (federated) input.

Looks up addr in the IANA Special-Purpose Address Registry and applies Ktistec's SSRF policy to the most-specific match:

  • No match: address is in unallocated/globally-reachable space per IANA convention → allow.
  • Matched entry's globally_reachable is false → reject.
  • Matched entry's globally_reachable is true but the entry is in the application policy set → reject.
  • Otherwise → allow.
Source

Nested types