rsolr 1.1.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,74 +0,0 @@
1
- require 'net/http'
2
- require 'net/https'
3
-
4
- # The default/Net::Http adapter for RSolr.
5
- class RSolr::Connection
6
-
7
- # using the request_context hash,
8
- # send a request,
9
- # then return the standard rsolr response hash {:status, :body, :headers}
10
- def execute client, request_context
11
- h = http request_context[:uri], request_context[:proxy], request_context[:read_timeout], request_context[:open_timeout]
12
- request = setup_raw_request request_context
13
- request.body = request_context[:data] if request_context[:method] == :post and request_context[:data]
14
- begin
15
- response = h.request request
16
- charset = response.type_params["charset"]
17
- {:status => response.code.to_i, :headers => response.to_hash, :body => force_charset(response.body, charset)}
18
- rescue Errno::ECONNREFUSED
19
- raise RSolr::Error::ConnectionRefused, request_context.inspect
20
- # catch the undefined closed? exception -- this is a confirmed ruby bug
21
- rescue NoMethodError => e
22
- e.message == "undefined method `closed?' for nil:NilClass" ?
23
- raise(RSolr::Error::ConnectionRefused, request_context.inspect) :
24
- raise(e)
25
- end
26
- end
27
-
28
- protected
29
-
30
- # This returns a singleton of a Net::HTTP or Net::HTTP.Proxy request object.
31
- def http uri, proxy = nil, read_timeout = nil, open_timeout = nil
32
- http = if proxy
33
- proxy_user, proxy_pass = proxy.userinfo.split(/:/) if proxy.userinfo
34
- Net::HTTP.Proxy(proxy.host, proxy.port, proxy_user, proxy_pass).new uri.host, uri.port
35
- elsif proxy == false
36
- # If explicitly passing in false, make sure we set proxy_addr to nil
37
- # to tell Net::HTTP to *not* use the environment proxy variables.
38
- Net::HTTP.new uri.host, uri.port, nil
39
- else
40
- Net::HTTP.new uri.host, uri.port
41
- end
42
- http.use_ssl = uri.port == 443 || uri.instance_of?(URI::HTTPS)
43
- http.read_timeout = read_timeout if read_timeout
44
- http.open_timeout = open_timeout if open_timeout
45
- http
46
- end
47
-
48
- #
49
- def setup_raw_request request_context
50
- http_method = case request_context[:method]
51
- when :get
52
- Net::HTTP::Get
53
- when :post
54
- Net::HTTP::Post
55
- when :head
56
- Net::HTTP::Head
57
- else
58
- raise "Only :get, :post and :head http method types are allowed."
59
- end
60
- headers = request_context[:headers] || {}
61
- raw_request = http_method.new request_context[:uri].request_uri
62
- raw_request.initialize_http_header headers
63
- raw_request.basic_auth(request_context[:uri].user, request_context[:uri].password) if request_context[:uri].user && request_context[:uri].password
64
- raw_request
65
- end
66
-
67
- private
68
-
69
- def force_charset body, charset
70
- return body unless charset and body.respond_to?(:force_encoding)
71
- body.force_encoding(charset)
72
- end
73
-
74
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
- # @deprecated remove this module's specs when we remove the method (duh)
3
- describe "RSolr::Char" do
4
-
5
- let(:char){Object.new.extend RSolr::Char}
6
-
7
- # deprecated as of 2015-02, as it is incorrect Solr escaping.
8
- # instead, use RSolr.solr_escape
9
- # commented out as it gives a mess of deprecation warnings
10
- =begin
11
- it 'should escape everything that is not a word with \\' do
12
- (0..255).each do |ascii|
13
- chr = ascii.chr
14
- esc = char.escape(chr)
15
- if chr =~ /\W/
16
- expect(esc.to_s).to eq("\\#{chr}")
17
- else
18
- expect(esc.to_s).to eq(chr)
19
- end
20
- end
21
- end
22
- =end
23
- end
@@ -1,140 +0,0 @@
1
- require 'spec_helper'
2
- require 'base64'
3
-
4
- describe "RSolr::Connection" do
5
-
6
- context "setup_raw_request" do
7
- it "should set the correct request parameters" do
8
- c = RSolr::Connection.new
9
- base_url = "http://localhost:8983/solr"
10
- client = RSolr::Client.new c, :url => base_url
11
- req = c.send :setup_raw_request, {:headers => {"content-type" => "text/xml"}, :method => :get, :uri => URI.parse(base_url + "/select?q=*:*")}
12
- expect(req.path).to eq("/solr/select?q=*:*")
13
- headers = {}
14
- req.each_header{|k,v| headers[k] = v}
15
- expect(headers).to eq({"content-type"=>"text/xml"})
16
- end
17
- end
18
-
19
- context "when the connection is refused" do
20
- subject { RSolr::Connection.new }
21
-
22
- it "raises a custom exception" do
23
- http_stub = double("Net:HTTP")
24
- allow(http_stub).to receive(:request).and_raise(Errno::ECONNREFUSED)
25
-
26
- allow(subject).to receive(:setup_raw_request) { http_stub }
27
- allow(subject).to receive(:http) { Net::HTTP.new("localhost", 80) }
28
-
29
- expect { subject.execute(nil, {}) }.to raise_error(RSolr::Error::ConnectionRefused)
30
- end
31
- end
32
-
33
- context "read timeout configuration" do
34
- let(:client) { double.as_null_object }
35
-
36
- let(:http) { double(Net::HTTP).as_null_object }
37
-
38
- subject { RSolr::Connection.new }
39
-
40
- before do
41
- allow(Net::HTTP).to receive(:new) { http }
42
- end
43
-
44
- it "should configure Net:HTTP read_timeout" do
45
- expect(http).to receive(:read_timeout=).with(42)
46
- subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :read_timeout => 42}
47
- end
48
-
49
- it "should use Net:HTTP default read_timeout if not specified" do
50
- expect(http).not_to receive(:read_timeout=)
51
- subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get}
52
- end
53
- end
54
-
55
- context "open timeout configuration" do
56
- let(:client) { double.as_null_object }
57
-
58
- let(:http) { double(Net::HTTP).as_null_object }
59
-
60
- subject { RSolr::Connection.new }
61
-
62
- before do
63
- allow(Net::HTTP).to receive(:new) { http }
64
- end
65
-
66
- it "should configure Net:HTTP open_timeout" do
67
- expect(http).to receive(:open_timeout=).with(42)
68
- subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :open_timeout => 42}
69
- end
70
-
71
- it "should use Net:HTTP default open_timeout if not specified" do
72
- expect(http).not_to receive(:open_timeout=)
73
- subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get}
74
- end
75
- end
76
-
77
- context "proxy configuration" do
78
- let(:client) { double.as_null_object }
79
-
80
- let(:http) { double(Net::HTTP).as_null_object }
81
-
82
- let(:uri) { URI.parse("http://localhost/some_url") }
83
- let(:proxy) { URI.parse("http://my.proxy/") }
84
-
85
- subject { RSolr::Connection.new }
86
-
87
- it "should use the default if no proxy is provided" do
88
- expect(Net::HTTP).to receive(:new).with(uri.host, uri.port) { http }
89
- subject.execute client, { :uri => uri, :method => :get }
90
- end
91
-
92
- it "should use the proxy if one is provided" do
93
- expect(Net::HTTP).to receive(:Proxy).with(proxy.host, proxy.port, nil, nil) { http }
94
- subject.execute client, { :uri => uri, :proxy => proxy, :method => :get }
95
- end
96
-
97
- it "should not use a proxy if proxy setting is false" do
98
- expect(Net::HTTP).to receive(:new).with(uri.host, uri.port, nil) { http }
99
- subject.execute client, { :uri => uri, :proxy => false, :method => :get }
100
- end
101
- end
102
-
103
- context "connection refused" do
104
- let(:client) { double.as_null_object }
105
-
106
- let(:http) { double(Net::HTTP).as_null_object }
107
- let(:request_context) {
108
- {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :open_timeout => 42}
109
- }
110
- subject { RSolr::Connection.new }
111
-
112
- before do
113
- allow(Net::HTTP).to receive(:new) { http }
114
- end
115
-
116
- it "should configure Net:HTTP open_timeout" do
117
- skip "doesn't work with ruby 1.8" if RUBY_VERSION < "1.9"
118
- expect(http).to receive(:request).and_raise(Errno::ECONNREFUSED)
119
- expect {
120
- subject.execute client, request_context
121
- }.to raise_error(Errno::ECONNREFUSED, /#{request_context}/)
122
- end
123
- end
124
-
125
- describe "basic auth support" do
126
- let(:http) { double(Net::HTTP).as_null_object }
127
-
128
- before do
129
- allow(Net::HTTP).to receive(:new) { http }
130
- end
131
-
132
- it "sets the authorization header" do
133
- expect(http).to receive(:request) do |request|
134
- expect(request.fetch('authorization')).to eq("Basic #{Base64.encode64("joe:pass")}".strip)
135
- double(Net::HTTPResponse).as_null_object
136
- end
137
- RSolr::Connection.new.execute nil, :uri => URI.parse("http://joe:pass@localhost:8983/solr"), :method => :get
138
- end
139
- end
140
- end
data/tasks/rdoc.rake DELETED
@@ -1,11 +0,0 @@
1
- # Rdoc
2
- require "rdoc/task"
3
-
4
- desc 'Generate documentation for the rsolr gem.'
5
- RDoc::Task.new(:doc) do |rdoc|
6
- rdoc.rdoc_dir = 'doc'
7
- rdoc.title = 'RSolr'
8
- rdoc.options << '--line-numbers' << '--inline-source'
9
- rdoc.rdoc_files.include('README.rdoc')
10
- rdoc.rdoc_files.include('lib/**/*.rb')
11
- end
data/tasks/rsolr.rake DELETED
@@ -1,10 +0,0 @@
1
- namespace :rsolr do
2
-
3
- namespace :solr do
4
- desc "Starts the HTTP server (port 9999) used for running HTTP connection tests"
5
- task :start do
6
- system "cd jetty; java -jar start.jar"
7
- end
8
- end
9
-
10
- end
data/tasks/spec.rake DELETED
@@ -1,2 +0,0 @@
1
- require 'rspec/core/rake_task'
2
- RSpec::Core::RakeTask.new(:spec)