ex_http_link v0.1.2 ExHttpLink View Source
Library for the HTTP Link header as specified in RFC 5988 "Web Linking".
Link to this section Summary
Link to this section Functions
Link to this function
generate(links) View Source
Generate a Link header.
Examples
iex> ExHttpLink.generate [ { "http://example.com", {"rel", "example"}, {"rev", "test"} } ]
~S(<http://example.com>; rel="example"; rev="test")
iex> ExHttpLink.generate [ { "http://example.com/a b c?x=y", {"rel", "example"} } ]
~S(<http://example.com/a%20b%20c?x=y>; rel="example")
iex> ExHttpLink.generate [ { "http://example.com/a%20b%20c?x=y", {"rel", "example"} } ]
~S(<http://example.com/a%20b%20c?x=y>; rel="example")
iex> ExHttpLink.generate [ { "http://example.com", {"rel", "example"} }, { "te.st", {"a", "b"}, {"c", ""} } ]
~S(<http://example.com>; rel="example", <te.st>; a="b"; c="")
iex> ExHttpLink.generate [ { "te.st", {"a", ~S(hello "world")} } ]
~S(<te.st>; a="hello%20%22world%22")
Link to this function
links_parsec(binary, opts \\ [])
View Source
links_parsec(binary, opts \\ [])
View Source
links_parsec(binary(), keyword()) ::
{:ok, [term()], rest, context, line, byte_offset}
| {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
byte_offset: pos_integer(),
rest: binary(),
reason: String.t(),
context: map()
links_parsec(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: pos_integer(), rest: binary(), reason: String.t(), context: map()
Parses the given binary
as links_parsec.
Returns {:ok, [token], rest, context, position, byte_offset}
or
{:error, reason, rest, context, line, byte_offset}
where position
describes the location of the links_parsec (start position) as {line, column_on_line}.
Options
:line
- the initial line, defaults to 1:byte_offset
- the initial byte offset, defaults to 0:context
- the initial context value. It will be converted to a map
Link to this function
parse(header) View Source
Parse a Link header.
Examples
iex> ExHttpLink.parse ~S(<http://example.com>; rel="example"; rev=test)
{:ok, [ { "http://example.com", {"rel", "example"}, {"rev", "test"} } ]}
iex> ExHttpLink.parse ~S(<yolo.swag>; whatEver="", <http://dev/null>; rel=next)
{:ok, [ { "yolo.swag", {"whatEver", ""} }, { "http://dev/null", {"rel", "next"} } ]}
iex> ExHttpLink.parse ~S(<yolo.swag>; title="some \" thing \" %22stuff%22 ")
{:ok, [ { "yolo.swag", {"title", "some \" thing \" \"stuff\" "} } ]}
iex> ExHttpLink.parse ~S( < http://example.com >;rel= "example"; title ="example dot com" )
{:ok, [ { "http://example.com", {"rel", "example"}, {"title", "example dot com"} } ]}
iex> ExHttpLink.parse ~S(<wat>; title*=UTF-8'de'n%c3%a4chstes%20Kapitel)
{:ok, [ { "wat", {"title*", "UTF-8'de'n%c3%a4chstes%20Kapitel"} } ]}