Skip to content

Commit

Permalink
Allow setting default headers in fedora.yml config
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcolvar committed May 8, 2024
1 parent 1a6a04e commit c4802f7
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 c4802f7

Please sign in to comment.