1
0
Fork 0
mirror of https://github.com/edgurgel/httparrot synced 2025-04-05 16:22:32 -04:00
httparrot/lib/httparrot/cookies_handler.ex
2016-09-15 12:13:50 +12:00

20 lines
502 B
Elixir

defmodule HTTParrot.CookiesHandler do
@moduledoc """
Returns cookie data.
"""
use HTTParrot.Cowboy, methods: ~w(GET HEAD OPTIONS)
def content_types_provided(req, state) do
{[{{"application", "json", []}, :get_json}], req, state}
end
def get_json(req, state) do
{cookies, req} = :cowboy_req.cookies(req)
cookies = if cookies == [], do: [{}], else: cookies
{response(cookies), req, state}
end
defp response(cookies) do
[cookies: cookies] |> JSX.encode!
end
end