View Source ExHttpLink (ex_http_link v0.1.4)
Library for the HTTP Link header as specified in RFC 5988 "Web Linking".
Link to this section Summary
Link to this section Functions
Generate a Link header.
examples
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")
@spec 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, offset_to_start_of_line}
.
To column where the error occurred can be inferred from byte_offset - offset_to_start_of_line
.
options
Options
:byte_offset
- the byte offset for the whole binary, defaults to 0:line
- the line and the byte offset into that line, defaults to{1, byte_offset}
:context
- the initial context value. It will be converted to a map
Parse a Link header.
examples
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"} } ]}