Packages

Conditional HTTP requests for Plug-based services

Current section

Files

Jump to
frugality lib frugality generator default.ex
Raw

lib/frugality/generator/default.ex

defmodule Frugality.Generator.Default do
@moduledoc false
alias Frugality.Core.Utils
@behaviour Frugality.Generator
@impl true
def etag(%{etag: etag}) when is_binary(etag),
do: Utils.parse_entity_tag(etag)
def etag(%{etag: {validation, tag} = etag})
when validation in [:weak, :strong] and is_binary(tag),
do: etag
def etag(_), do: nil
@impl true
def last_modified(%{last_modified: dt}) when is_binary(dt),
do: Utils.parse_httpdate(dt)
def last_modified(%{last_modified: %s{} = dt})
when s in [DateTime, NaiveDateTime],
do: dt
def last_modified(_), do: nil
end