chulkilee

chulkilee

Parsing HTTP Link header with NimbleParsec

Hi - I implemented HTTP Link header parser with nimble_parsec. I know there is ex_link_header but just took it as a chance to use the parser library :slight_smile:

Here is the gist link - any feedback would be welcome!

  • As , is not allowed, I may just split the whole string with , - but not sure I can leverage existing tool to handle optionally escaped string (e.g. Plug.Conn.Utils.params)
  • Probably I can switch all string with ascii_char since only ascii chars are allowed in the value
  • Not sure I’m using wrap/unwrap correctly :wink:
  • I do not want to create another “micro” library. What would be better place to put this? plug, phoenix, standalone package to cover HTTP headers

Marked As Solved

valpackett

valpackett

haha, I already did (initially published to hex @ March 30, 2019):

but it has a generator as well as a parser. The forum showed me this thread as related when I was creating that thread about it :slight_smile:

Also Liked

LostKobrakai

LostKobrakai

NimbleParsec can output the compiled module, so users don’t need nimble_parsec as dependency, if that’s the reasoning here.

chulkilee

chulkilee

Another naive example at Tesla.Middleware.DecodeRels:"

src

  defp rels(link) do
    link
    |> String.split(",")
    |> Enum.map(&String.trim/1)
    |> Enum.map(&rel/1)
    |> Enum.into(%{})
  end

  defp rel(item) do
    Regex.run(~r/\A<(.+)>; rel="(.+)"\z/, item, capture: :all_but_first)
    |> Enum.reverse()
    |> List.to_tuple()
  end

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement