Add Last Modified header

This commit is contained in:
Hakan Ensari 2015-09-15 12:01:16 +01:00
parent c1f2ed25e7
commit 5094956f7c
2 changed files with 13 additions and 0 deletions

View File

@ -53,11 +53,14 @@ get '/' do
end
get '/latest' do
last_modified quote[:date]
jsonp quote
end
get(/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/) do
transform_date
last_modified quote[:date]
jsonp quote
end

View File

@ -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']