1
0
Fork 0
mirror of https://github.com/edgurgel/httparrot synced 2025-04-09 11:42:33 -04:00
httparrot/lib/httparrot/cache_handler.ex
2014-07-22 20:33:22 +12:00

24 lines
636 B
Elixir

defmodule HTTParrot.CacheHandler do
@moduledoc """
Returns 200 unless an If-Modified-Since or If-None-Match header is provided, when it returns a 304.
"""
alias HTTParrot.GeneralRequestInfo
use HTTParrot.Cowboy, methods: ~w(GET HEAD OPTIONS)
def last_modified(req, state) do
{{{2012, 9, 21}, {22, 36, 14}}, req, state}
end
def content_types_provided(req, state) do
{[{{"application", "json", []}, :get_json}], req, state}
end
def get_json(req, state) do
{info, req} = GeneralRequestInfo.retrieve(req)
{response(info), req, state}
end
defp response(info) do
info |> JSEX.encode!
end
end