Class: RestClient::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/couchrest/monkeypatches.rb

Instance Method Summary collapse

Instance Method Details

#transmit(uri, req, payload) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/couchrest/monkeypatches.rb', line 58

def transmit(uri, req, payload)
	setup_credentials(req)
	
	Thread.current[:host] ||= uri.host
    Thread.current[:port] ||= uri.port

	net = net_http_class.new(uri.host, uri.port)
    
    if Thread.current[:connection].nil? || Thread.current[:host] != uri.host
      Thread.current[:connection].finish if (Thread.current[:connection] && Thread.current[:connection].started?)
      net.use_ssl = uri.is_a?(URI::HTTPS)
      net.verify_mode = OpenSSL::SSL::VERIFY_NONE
      Thread.current[:connection] = net
      Thread.current[:connection].start
    end

	display_log request_log
    http = Thread.current[:connection]

    http.read_timeout = @timeout if @timeout
    begin
			res = http.request(req, payload)
		rescue
		  # p "Net::HTTP connection failed, reconnecting"
		  Thread.current[:connection].finish
		  http = Thread.current[:connection] = net
      Thread.current[:connection].start
      res = http.request(req, payload)
      display_log response_log(res)
			process_result res
  else
			display_log response_log(res)
			process_result res
		end
	
rescue EOFError
	raise RestClient::ServerBrokeConnection
rescue Timeout::Error
	raise RestClient::RequestTimeout
end