Image.Plug.SourceResolver behaviour (image_plug v0.1.0)

Copy Markdown View Source

Behaviour for source resolvers.

A resolver turns a Image.Plug.Source.t/0 into an open Vix.Vips.Image plus a small bag of metadata used for HTTP cache headers (content_type, etag_seed, optionally last_modified and byte_size).

A resolver typically handles one Image.Plug.Source kind. The default Image.Plug.SourceResolver.Composite dispatches by kind to a configured set of per-kind resolvers.

Summary

Types

Metadata about the resolved source. The plug uses these values to build cache headers and to fingerprint the response for ETag computation.

Callbacks

Loads the source bytes referenced by source and opens them as a Vix.Vips.Image.

Types

meta()

@type meta() :: %{
  :content_type => String.t(),
  :etag_seed => binary(),
  optional(:last_modified) => DateTime.t(),
  optional(:byte_size) => non_neg_integer(),
  optional(:cache_control) => String.t(),
  optional(:immutable?) => boolean()
}

Metadata about the resolved source. The plug uses these values to build cache headers and to fingerprint the response for ETag computation.

  • :content_type — the MIME type of the source bytes.

  • :etag_seed — any stable per-source binary. Image.Plug.Cache hashes this together with the pipeline fingerprint to compute the response ETag.

  • :last_modified — optional DateTime to emit as Last-Modified.

  • :byte_size — optional integer; informational.

  • :cache_control — optional Cache-Control directive to forward on the response.

  • :immutable? — if true, the cache layer may add immutable.

Callbacks

load(t, options)

@callback load(Image.Plug.Source.t(), options :: keyword()) ::
  {:ok, Vix.Vips.Image.t(), meta()} | {:error, Image.Plug.Error.t()}

Loads the source bytes referenced by source and opens them as a Vix.Vips.Image.

Returns the open image plus a meta/0 map.