add http config to DiasporaFederation
This commit is contained in:
parent
0917fc2f19
commit
1cc8fac8a1
2 changed files with 41 additions and 3 deletions
|
|
@ -33,6 +33,13 @@ module DiasporaFederation
|
||||||
save_entity_after_receive
|
save_entity_after_receive
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# defaults
|
||||||
|
@http_concurrency = 20
|
||||||
|
@http_timeout = 30
|
||||||
|
@http_verbose = false
|
||||||
|
@http_redirect_limit = 4
|
||||||
|
@http_user_agent = "DiasporaFederation/#{DiasporaFederation::VERSION}"
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# {Callbacks} instance with defined callbacks
|
# {Callbacks} instance with defined callbacks
|
||||||
# @see Callbacks#on
|
# @see Callbacks#on
|
||||||
|
|
@ -53,6 +60,27 @@ module DiasporaFederation
|
||||||
# config.certificate_authorities = AppConfig.environment.certificate_authorities.get
|
# config.certificate_authorities = AppConfig.environment.certificate_authorities.get
|
||||||
attr_accessor :certificate_authorities
|
attr_accessor :certificate_authorities
|
||||||
|
|
||||||
|
# Maximum number of parallel HTTP requests made to other pods
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# config.http_concurrency = AppConfig.settings.typhoeus_concurrency.to_i
|
||||||
|
attr_accessor :http_concurrency
|
||||||
|
|
||||||
|
# timeout in seconds for http-requests
|
||||||
|
attr_accessor :http_timeout
|
||||||
|
|
||||||
|
# Turn on extra verbose output when sending stuff.
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# config.http_verbose = AppConfig.settings.typhoeus_verbose?
|
||||||
|
attr_accessor :http_verbose
|
||||||
|
|
||||||
|
# max redirects to follow
|
||||||
|
attr_reader :http_redirect_limit
|
||||||
|
|
||||||
|
# user agent used for http-requests
|
||||||
|
attr_reader :http_user_agent
|
||||||
|
|
||||||
# configure the federation library
|
# configure the federation library
|
||||||
#
|
#
|
||||||
# @example
|
# @example
|
||||||
|
|
@ -167,6 +195,8 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
validate_http_config
|
||||||
|
|
||||||
unless @callbacks.definition_complete?
|
unless @callbacks.definition_complete?
|
||||||
configuration_error "Missing handlers for #{@callbacks.missing_handlers.join(', ')}"
|
configuration_error "Missing handlers for #{@callbacks.missing_handlers.join(', ')}"
|
||||||
end
|
end
|
||||||
|
|
@ -176,6 +206,14 @@ module DiasporaFederation
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def validate_http_config
|
||||||
|
configuration_error "http_concurrency: please configure a number" unless @http_concurrency.is_a?(Fixnum)
|
||||||
|
configuration_error "http_timeout: please configure a number" unless @http_timeout.is_a?(Fixnum)
|
||||||
|
|
||||||
|
return unless !@http_verbose.is_a?(TrueClass) && !@http_verbose.is_a?(FalseClass)
|
||||||
|
configuration_error "http_verbose: please configure a boolean"
|
||||||
|
end
|
||||||
|
|
||||||
def configuration_error(message)
|
def configuration_error(message)
|
||||||
logger.fatal("diaspora federation configuration error: #{message}")
|
logger.fatal("diaspora federation configuration error: #{message}")
|
||||||
raise ConfigurationError, message
|
raise ConfigurationError, message
|
||||||
|
|
|
||||||
|
|
@ -25,16 +25,16 @@ module DiasporaFederation
|
||||||
|
|
||||||
def self.create_default_connection
|
def self.create_default_connection
|
||||||
options = {
|
options = {
|
||||||
request: {timeout: 30},
|
request: {timeout: DiasporaFederation.http_timeout},
|
||||||
ssl: {ca_file: DiasporaFederation.certificate_authorities}
|
ssl: {ca_file: DiasporaFederation.certificate_authorities}
|
||||||
}
|
}
|
||||||
|
|
||||||
@connection = Faraday::Connection.new(options) do |builder|
|
@connection = Faraday::Connection.new(options) do |builder|
|
||||||
builder.use FaradayMiddleware::FollowRedirects, limit: 4
|
builder.use FaradayMiddleware::FollowRedirects, limit: DiasporaFederation.http_redirect_limit
|
||||||
builder.adapter Faraday.default_adapter
|
builder.adapter Faraday.default_adapter
|
||||||
end
|
end
|
||||||
|
|
||||||
@connection.headers["User-Agent"] = "DiasporaFederation/#{DiasporaFederation::VERSION}"
|
@connection.headers["User-Agent"] = DiasporaFederation.http_user_agent
|
||||||
end
|
end
|
||||||
private_class_method :create_default_connection
|
private_class_method :create_default_connection
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue