Merge pull request #150 from 5apps/feature/cors_preflight_max_age

Allow clients to cache OPTIONS results for 2 hours
This commit is contained in:
Basti 2022-05-13 19:21:08 +02:00 committed by GitHub
commit 38b8a4d3eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -79,6 +79,7 @@ class LiquorCabinet < Sinatra::Base
end
options path do
headers['Access-Control-Max-Age'] = '7200'
halt 200
end
end

View File

@ -14,6 +14,18 @@ shared_examples_for 'a REST adapter' do
_(last_response.status).must_equal 404
end
describe "OPTIONS requests" do
it "returns CORS headers" do
options "/phil/food/aguacate"
_(last_response.headers["Access-Control-Allow-Origin"]).wont_be_nil
_(last_response.headers["Access-Control-Allow-Methods"]).must_equal "GET, PUT, DELETE"
_(last_response.headers["Access-Control-Max-Age"].to_i).must_be :> , 10
end
end
describe "PUT requests" do
before do