def request(request_params, &block)
mypos = get_fileptr_offset(request_params)
loop do
if error_count > @params[:http_connection_retry_count] &&
error_time + @params[:http_connection_retry_delay] > Time.now
banana_message_text = banana_message
@logger.warn("#{err_header} re-raising same error: #{banana_message_text} " +
"-- error count: #{error_count}, error age: #{Time.now.to_i - error_time.to_i}")
exception = get_param(:exception) || RuntimeError
raise exception.new(banana_message_text)
end
begin
request_params[:protocol] ||= (request_params[:port] == 443 ? 'https' : 'http')
request = request_params[:request]
request['User-Agent'] = get_param(:user_agent) || ''
unless @http &&
@http.started? &&
@server == request_params[:server] &&
@port == request_params[:port] &&
@protocol == request_params[:protocol]
start(request_params)
end
setup_streaming(request)
response = @http.request(request, &block)
error_reset
eof_reset
return response
rescue EOFError => e
@logger.debug("#{err_header} server #{@server} closed connection")
@http = nil
if raise_on_eof_exception?
exception = get_param(:exception) || RuntimeError
@logger.warn("#{err_header} raising #{exception} due to permanent EOF being received from #{@server}, error age: #{Time.now.to_i - eof_time.to_i}")
raise exception.new("Permanent EOF is being received from #{@server}.")
else
sleep(add_eof)
reset_fileptr_offset(request, mypos)
end
rescue Exception => e
@http = nil
if e.is_a?(Interrupt) && !(e.is_a?(Errno::ETIMEDOUT) || e.is_a?(Timeout::Error))
@logger.debug("#{err_header} request to server #{@server} interrupted by ctrl-c")
raise
elsif e.is_a?(ArgumentError) && e.message.include?('wrong number of arguments (5 for 4)')
exception = get_param(:exception) || RuntimeError
raise exception.new('incompatible Net::HTTP monkey-patch')
end
error_add(e.message)
@logger.warn("#{err_header} request failure count: #{error_count}, exception: #{e.inspect}")
reset_fileptr_offset(request, mypos)
end
end
end