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

Copy Markdown View Source

Source resolver that streams images from http(s):// URLs.

Decoding is streaming-friendly: the body flows from the socket into libvips chunk-by-chunk via Image.from_req_stream/2, which uses Req.get/2 with into: :self and feeds bytes into Vix.Vips.Image.new_from_enum/1.

Configuration

  • :allowed_hosts (required) — list of hostname strings the resolver will fetch from. Hosts not on the list are rejected with :invalid_option. Pass :any to disable the allow-list (only sensible when this resolver sits behind a host-supplied auth/auditing layer).

  • :timeout — milliseconds to wait between chunks. Defaults to 5_000 (the Image.from_req_stream/2 default).

Limitations (v0.1)

  • The streaming decode path does not surface response headers to the caller, so the resolver cannot populate :last_modified or forward an upstream ETag. The etag_seed is derived from the request URL itself, which gives a stable per-URL ETag without a second pass over the body. A future milestone may switch to a two-stage HEAD-then-GET when freshness signals are required.

  • Response body size is bounded by whatever limits the configured Req request honours; we do not impose an additional cap in this resolver.

  • Requires the optional :req dependency. If Req is not loaded the resolver returns :not_implemented at request time.