Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/neo4j/core/cypher_session/adaptors/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(url, options = {})
end

def connect
@requestor = Requestor.new(@url, USER_AGENT_STRING, self.class.method(:instrument_request))
@requestor = Requestor.new(@url, USER_AGENT_STRING, self.class.method(:instrument_request), @options[:faraday_options] ||= {})
end

ROW_REST = %w(row REST)
Expand Down Expand Up @@ -101,13 +101,12 @@ class Requestor
include Adaptors::HasUri
default_url('http://neo4:neo4j@localhost:7474')
validate_uri { |uri| uri.is_a?(URI::HTTP) }

def initialize(url, user_agent_string, instrument_proc)
def initialize(url, user_agent_string, instrument_proc, faraday_options = {})
self.url = url
@user = user
@password = password
@user_agent_string = user_agent_string
@faraday = wrap_connection_failed! { faraday_connection }
@faraday = wrap_connection_failed! { faraday_connection(faraday_options.fetch(:initialize, {})) }
@instrument_proc = instrument_proc
end

Expand Down Expand Up @@ -144,12 +143,12 @@ def get(path, body = '', options = {})

private

def faraday_connection
def faraday_connection(options = {})
require 'faraday'
require 'faraday_middleware/multi_json'

Faraday.new(url) do |c|
c.request :basic_auth, user, password
Faraday.new(url, options) do |c|
c.request :basic_auth, config_username(user, options), config_password(password, options)
c.request :multi_json

c.response :multi_json, symbolize_keys: true, content_type: 'application/json'
Expand All @@ -162,6 +161,14 @@ def faraday_connection
end
end

def config_password(password, options)
options[:basic_auth] ? options[:basic_auth][:password] : password
end

def config_username(user, options)
options[:basic_auth] ? options[:basic_auth][:username] : user
end

def request_body(body)
return body if body.is_a?(String)

Expand Down