Philter.Config (Philter v0.3.0)

Copy Markdown View Source

Configuration management for Philter proxy library.

Configuration can be set at the application level and overridden per-request.

Application Configuration

config :philter,
  finch_name: MyApp.Finch,
  receive_timeout: 15_000,
  max_payload_size: 1_048_576,
  persistable_content_types: ["application/json", "text/xml", "text/*"]

Per-Request Overrides

Any option can be overridden when calling Philter.proxy/2:

Philter.proxy(conn,
  upstream: "http://api.example.com",
  receive_timeout: 30_000,
  max_payload_size: 5_242_880
)

Options

  • :finch_name - Name of the Finch pool to use (default: Philter.Finch)
  • :receive_timeout - Timeout in ms for receiving response (default: 15_000)
  • :max_payload_size - Max size in bytes for full body accumulation (default: 1_048_576 / 1MB)
  • :persistable_content_types - Content types eligible for full body storage (default: see below)
  • :log_level - Logger level for lifecycle events, or false to disable (default: :debug)

Default Persistable Content Types

By default, the following content types are eligible for full body accumulation:

  • application/json
  • application/xml
  • text/xml
  • text/plain
  • text/html

Wildcards like text/* are supported.

Summary

Functions

Checks if a content type is eligible for body accumulation.

Returns the configured Finch pool name.

Returns the log level for lifecycle events.

Returns the maximum payload size for full body accumulation in bytes.

Returns the list of content types eligible for full body accumulation.

Returns the receive timeout in milliseconds.

Returns all configuration as a map, with per-request overrides applied.

Types

t()

@type t() :: %{
  finch_name: atom(),
  receive_timeout: pos_integer(),
  max_payload_size: pos_integer(),
  persistable_content_types: [String.t()],
  log_level: Logger.level() | false
}

Functions

content_type_persistable?(content_type, allowed)

@spec content_type_persistable?(String.t() | nil, [String.t()]) :: boolean()

Checks if a content type is eligible for body accumulation.

Supports exact matches and wildcard patterns (e.g., text/*).

Examples

iex> Philter.Config.content_type_persistable?("application/json", ["application/json", "text/*"])
true

iex> Philter.Config.content_type_persistable?("text/plain", ["application/json", "text/*"])
true

iex> Philter.Config.content_type_persistable?("image/png", ["application/json", "text/*"])
false

finch_name(opts \\ [])

@spec finch_name(keyword()) :: atom()

Returns the configured Finch pool name.

Examples

iex> Philter.Config.finch_name()
Philter.Finch

iex> Philter.Config.finch_name(finch_name: MyApp.Finch)
MyApp.Finch

log_level(opts \\ [])

@spec log_level(keyword()) :: Logger.level() | false

Returns the log level for lifecycle events.

Set to false to disable all logging. Defaults to :debug.

Examples

iex> Philter.Config.log_level()
:debug

iex> Philter.Config.log_level(log_level: :info)
:info

iex> Philter.Config.log_level(log_level: false)
false

max_payload_size(opts \\ [])

@spec max_payload_size(keyword()) :: pos_integer()

Returns the maximum payload size for full body accumulation in bytes.

Examples

iex> Philter.Config.max_payload_size()
1_048_576

iex> Philter.Config.max_payload_size(max_payload_size: 5_242_880)
5_242_880

persistable_content_types(opts \\ [])

@spec persistable_content_types(keyword()) :: [String.t()]

Returns the list of content types eligible for full body accumulation.

Supports wildcard patterns like "text/*".

Examples

iex> Philter.Config.persistable_content_types() |> Enum.member?("application/json")
true

iex> Philter.Config.persistable_content_types(persistable_content_types: ["application/json"])
["application/json"]

receive_timeout(opts \\ [])

@spec receive_timeout(keyword()) :: pos_integer()

Returns the receive timeout in milliseconds.

Examples

iex> Philter.Config.receive_timeout()
15_000

iex> Philter.Config.receive_timeout(receive_timeout: 30_000)
30_000

resolve(opts \\ [])

@spec resolve(keyword()) :: t()

Returns all configuration as a map, with per-request overrides applied.

Useful for getting the full resolved config in one call.

Examples

iex> config = Philter.Config.resolve(receive_timeout: 30_000)
iex> config.receive_timeout
30_000