Skip to content

Commit

Permalink
Merge pull request #106 from curationexperts/metadata_options
Browse files Browse the repository at this point in the history
Add OPTIONS response for info.json
  • Loading branch information
val99erie authored Feb 23, 2018
2 parents 611c516 + cfceb47 commit f21f6c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/riiif/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def info
end
end

# See https://fetch.spec.whatwg.org/#http-access-control-allow-headers
def info_options
response.headers['Access-Control-Allow-Headers'] = 'Authorization'
self.response_body = ''
end

# this is a workaround for https://github.com/rails/rails/issues/25087
def redirect
# This was attempted with just info_path, but it gave a NoMethodError
Expand Down
3 changes: 3 additions & 0 deletions lib/riiif/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def draw
defaults: { format: 'json', model: resource },
as: [options[:as], 'info'].compact.join('_')

match "#{route_prefix}/:id/info.json" => 'riiif/images#info_options',
via: [:options]

# This doesn't work presently
# get "#{route_prefix}/:id", to: redirect("#{route_prefix}/%{id}/info.json")
get "#{route_prefix}/:id" => 'riiif/images#redirect', as: [options[:as], 'base'].compact.join('_')
Expand Down
8 changes: 8 additions & 0 deletions spec/controllers/riiif/images_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@
end
end

describe 'info_options' do
it 'is successful' do
process :info_options, method: 'OPTIONS', params: { id: 'abcd123', format: 'json' }
expect(response).to be_successful
expect(response.headers['Access-Control-Allow-Headers']).to eq 'Authorization'
end
end

describe 'info' do
context 'the happy path' do
let(:image) { double }
Expand Down

0 comments on commit f21f6c8

Please sign in to comment.