Kantoor.Feeds.Fetcher (Kantoor v1.0.0)

Gets a feed over HTTPS and says what came back, with every limit applied:

  • Where. Each host (the feed's, and the target of every redirect) is resolved and checked by Kantoor.Feeds.NetGuard; the connection goes to the checked address (Kantoor.Feeds.Http).
  • Redirects. At most 5 (:max_redirects), only to https addresses that pass Kantoor.Feeds.Url, and an address seen before in the chain is a loop.
  • Size and time. The body may be at most 5 MB (:max_bytes) and the whole fetch, redirects included, must end within 20 seconds (:timeout_ms).
  • Conditional. If-None-Match and If-Modified-Since are sent when the previous fetch gave an ETag or Last-Modified; a 304 is :not_modified.

The result is {:ok, %{body:, etag:, last_modified:}}, :not_modified or {:error, code, retry_after}. code is a short string ("timeout", "too_large", "not_public", "http_404", ...; see message/1) that never contains the address, so it can be stored, shown and logged. retry_after is the server's Retry-After in seconds when it sent one on a 429 or 503.

Summary

Functions

Fetches url (a normalised https address). Options: :max_redirects, :max_bytes, :timeout_ms.

The largest body accepted, in bytes.

English text for a fetch error code (the interface translates them).

Types

conditional()

@type conditional() :: %{
  optional(:etag) => String.t() | nil,
  optional(:last_modified) => String.t() | nil
}

ok()

@type ok() :: %{
  body: binary(),
  etag: String.t() | nil,
  last_modified: String.t() | nil
}

result()

@type result() ::
  {:ok, ok()} | :not_modified | {:error, String.t(), non_neg_integer() | nil}

Functions

fetch(url, conditional \\ %{}, opts \\ [])

@spec fetch(String.t(), conditional(), keyword()) :: result()

Fetches url (a normalised https address). Options: :max_redirects, :max_bytes, :timeout_ms.

max_bytes()

The largest body accepted, in bytes.

message(arg1)

@spec message(String.t()) :: String.t()

English text for a fetch error code (the interface translates them).