Class: RSolr::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/rsolr/connection.rb

Overview

The default/Net::Http adapter for RSolr.

Instance Method Summary collapse

Instance Method Details

#execute(client, request_context) ⇒ Object

using the request_context hash, send a request, then return the standard rsolr response hash :body, :headers


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rsolr/connection.rb', line 10

def execute client, request_context
  h = http request_context[:uri], request_context[:proxy], request_context[:read_timeout], request_context[:open_timeout]
  request = setup_raw_request request_context
  request.body = request_context[:data] if request_context[:method] == :post and request_context[:data]
  begin
    response = h.request request
    charset = response.type_params["charset"]
    {:status => response.code.to_i, :headers => response.to_hash, :body => force_charset(response.body, charset)}
  rescue Errno::ECONNREFUSED
    raise RSolr::Error::ConnectionRefused, request_context.inspect
  # catch the undefined closed? exception -- this is a confirmed ruby bug
  rescue NoMethodError => e
    e.message == "undefined method `closed?' for nil:NilClass" ?
      raise(RSolr::Error::ConnectionRefused, request_context.inspect) :
      raise(e)
  end
end