From 5094956f7c8d4878d20ba3cc72ce0ded5a5842f3 Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Tue, 15 Sep 2015 12:01:16 +0100 Subject: [PATCH] Add Last Modified header --- lib/api.rb | 3 +++ spec/api_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/api.rb b/lib/api.rb index 52c2701..66d8306 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -53,11 +53,14 @@ get '/' do end get '/latest' do + last_modified quote[:date] jsonp quote end get(/(?\d{4})-(?\d{2})-(?\d{2})/) do transform_date + last_modified quote[:date] + jsonp quote end diff --git a/spec/api_spec.rb b/spec/api_spec.rb index ab78554..e1a5eb3 100644 --- a/spec/api_spec.rb +++ b/spec/api_spec.rb @@ -40,6 +40,16 @@ describe 'the API' do json['rates'].wont_be :empty? end + it 'returns a last modified header for latest quote' do + get '/latest' + headers['Last-Modified'].wont_be_nil + end + + it 'returns a last modified header for historical quote' do + get '/2012-11-20' + headers['Last-Modified'].wont_be_nil + end + it 'allows cross-origin requests' do get '/', {}, 'HTTP_ORIGIN' => 'http://localhost' assert_equal 'http://localhost', headers['Access-Control-Allow-Origin']