1
0
Fork 0
mirror of https://github.com/edgurgel/httparrot synced 2025-04-06 00:32:34 -04:00
httparrot/lib/httparrot/user_agent_handler.ex
2015-02-09 21:13:20 +13:00

20 lines
491 B
Elixir

defmodule HTTParrot.UserAgentHandler do
@moduledoc """
Returns user-agent.
"""
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
{user_agent, req} = :cowboy_req.header("user-agent", req, "null")
{response(user_agent), req, state}
end
defp response(user_agent) do
[{"user-agent", user_agent}]
|> JSX.encode!
end
end