Alternera.Plugin.HeaderCatalogue (alternera_plugin_sdk v0.9.0)

Copy Markdown View Source

The HTTP headers an editor suggests when nothing was recorded: the common request and response header names, each with a line saying what it is, and the values typically written into each.

It is data, with no LiveView in it, so a step editor, a condition editor or the assistant can all read it. Alternera.Plugin.Editor.HeaderSuggestions turns it into what a <.suggest_input> reads, with the source exchange's recorded names put first.

Names are spelled the way documentation spells them (Content-Type); HTTP compares them ignoring case, and so do values/2 and the editors' merge with recorded names. The framing headers a proxy or its transport writes (Content-Length, Transfer-Encoding, Connection, TE, Upgrade, Keep-Alive) are left out: a step that sets them changes nothing or breaks the message.

A value may be only the start of one: Bearer ends in a space, so a pick leaves the cursor where the token goes.

Summary

Types

A header: its name, what it is, and its typical values (possibly none).

Which message a header is written into.

A value typically written into a header, with what it means.

Functions

The headers of side, sorted by name ignoring case.

The header names of side, in headers/1's order.

The typical values of the header name in side, matched ignoring case and surrounding blanks; [] for a header without any or not in the catalogue.

Types

header()

@type header() :: %{name: String.t(), description: String.t(), values: [value()]}

A header: its name, what it is, and its typical values (possibly none).

side()

@type side() :: :request | :response

Which message a header is written into.

value()

@type value() :: %{value: String.t(), description: String.t() | nil}

A value typically written into a header, with what it means.

Functions

headers(atom)

@spec headers(side()) :: [header()]

The headers of side, sorted by name ignoring case.

Examples

iex> Alternera.Plugin.HeaderCatalogue.headers(:request) |> Enum.map(& &1.name) |> Enum.take(2)
["Accept", "Accept-Encoding"]

names(side)

@spec names(side()) :: [String.t()]

The header names of side, in headers/1's order.

values(side, name)

@spec values(side(), String.t() | nil) :: [value()]

The typical values of the header name in side, matched ignoring case and surrounding blanks; [] for a header without any or not in the catalogue.

Examples

iex> Alternera.Plugin.HeaderCatalogue.values(:request, " content-type ") |> hd()
%{value: "application/json", description: "JSON"}