Skip to content

Commit

Permalink
Merge pull request #5826 from avalonmediasystem/fedora_headers
Browse files Browse the repository at this point in the history
Allow setting default headers in fedora.yml config
  • Loading branch information
cjcolvar authored May 10, 2024
2 parents 1a6a04e + c4802f7 commit eb8e7d4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions config/initializers/active_fedora_reindexing.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
ActiveFedora::Fedora.class_eval do
def header_options
@config[:headers]
end

def authorized_connection
options = {}
options[:ssl] = ssl_options if ssl_options
options[:request] = request_options if request_options
options[:headers] = header_options if header_options
Faraday.new(host, options) do |conn|
conn.response :encoding # use Faraday::Encoding middleware
conn.adapter Faraday.default_adapter # net/http
if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('2')
conn.request :basic_auth, user, password
else
conn.request :authorization, :basic, user, password
end
end
end

def ntriples_connection
authorized_connection.tap { |conn| conn.headers['Accept'] = 'application/n-triples' }
end
Expand Down

0 comments on commit eb8e7d4

Please sign in to comment.