Class: Wire::NetHTTPAdapter
- Inherits:
-
Object
- Object
- Wire::NetHTTPAdapter
- Defined in:
- lib/wire/client.rb
Overview
NetHTTPAdapter is the default transport, built on stdlib Net::HTTP.
Instance Method Summary collapse
Instance Method Details
#call(method, uri, headers, body, timeout) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/wire/client.rb', line 145 def call(method, uri, headers, body, timeout) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == "https") http.open_timeout = timeout http.read_timeout = timeout http.write_timeout = timeout if http.respond_to?(:write_timeout=) req = build_request(method, uri, headers, body) begin res = http.request(req) rescue Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout => e raise Wire::TimeoutError, "request timed out: #{e.}" rescue SocketError, SystemCallError, IOError, OpenSSL::SSL::SSLError => e raise Wire::ConnectionError, "request failed: #{e.}" end Wire::Response.new( status: res.code.to_i, headers: normalize_headers(res), body: res.body ) end |