Class: HTTPI::Adapter::NetHTTP
- Defined in:
- lib/httpi/adapter/net_http.rb
Overview
HTTPI::Adapter::NetHTTP
Adapter for the Net::HTTP client. ruby-doc.org/stdlib/libdoc/net/http/rdoc/
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(request) ⇒ NetHTTP
constructor
A new instance of NetHTTP.
-
#request(method) ⇒ Object
Executes arbitrary HTTP requests.
Methods inherited from Base
Constructor Details
#initialize(request) ⇒ NetHTTP
Returns a new instance of NetHTTP.
18 19 20 21 22 |
# File 'lib/httpi/adapter/net_http.rb', line 18 def initialize(request) check_net_ntlm_version! if request.auth.ntlm? @request = request @client = create_client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
24 25 26 |
# File 'lib/httpi/adapter/net_http.rb', line 24 def client @client end |
Instance Method Details
#request(method) ⇒ Object
Executes arbitrary HTTP requests.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/httpi/adapter/net_http.rb', line 28 def request(method) # Determine if Net::HTTP supports the method using reflection unless Net::HTTP.const_defined?(:"#{method.to_s.capitalize}") && Net::HTTP.const_get(:"#{method.to_s.capitalize}").class == Class raise NotSupportedError, "Net::HTTP does not support "\ "#{method.to_s.upcase}" end do_request(method) do |http, http_request| http_request.body = @request.body if @request.on_body then perform(http, http_request) do |res| res.read_body do |seg| @request.on_body.call(seg) end end else perform(http, http_request) end end rescue OpenSSL::SSL::SSLError raise SSLError rescue Errno::ECONNREFUSED # connection refused $!.extend ConnectionError raise end |