Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: main tests
name: 8.4 tests
on:
push:
branches:
- main
- 8.4
pull_request:
branches:
- main
- 8.4
workflow_dispatch:
jobs:
test:
Expand All @@ -16,8 +16,8 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ['3.2', '3.3', '3.4', 'jruby-9.3', 'jruby-9.4', 'jruby-10.0']
es_version: ['8.18.8-SNAPSHOT', '8.19.5-SNAPSHOT', '9.0.8-SNAPSHOT', '9.1.5-SNAPSHOT', '9.2.0-SNAPSHOT']
ruby: ['3.2', '3.3', '3.4', '4.0', 'jruby-9.3', 'jruby-9.4', 'jruby-10.0']
es_version: ['8.19.14-SNAPSHOT', '9.2.9-SNAPSHOT', '9.3.4-SNAPSHOT', '9.4.0-SNAPSHOT', '9.5.0-SNAPSHOT']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
7 changes: 5 additions & 2 deletions elastic-transport.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ Gem::Specification.new do |s|
s.add_dependency 'multi_json'

# Faraday Adapters
s.add_development_dependency 'manticore' if defined? JRUBY_VERSION
if defined? JRUBY_VERSION
s.add_development_dependency 'base64'
s.add_development_dependency 'manticore'
end
s.add_development_dependency 'curb' unless defined? JRUBY_VERSION
s.add_development_dependency 'bundler'
s.add_development_dependency 'cane'
Expand All @@ -63,7 +66,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'shoulda-context'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'test-unit', '~> 2'
s.add_development_dependency 'yard'
s.add_development_dependency 'yard', '> 0.9.42'

s.description = <<-DESC.gsub(/^ /, '')
Low level Ruby client for Elastic. See the `elasticsearch` or `elastic-enterprise-search` gems for full integration.
Expand Down
20 changes: 13 additions & 7 deletions lib/elastic/transport/transport/http/curb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ def perform_request(method, path, params = {}, body = nil, headers = nil, opts =
connection.connection.set :nobody, false
connection.connection.put_data = body if body

if headers
if connection.connection.headers
connection.connection.headers.merge!(headers)
else
connection.connection.headers = headers
end
end
parse_headers!(headers, connection)
else raise ArgumentError, "Unsupported HTTP method: #{method}"
end

Expand All @@ -68,6 +62,18 @@ def perform_request(method, path, params = {}, body = nil, headers = nil, opts =
end
end

# Merges headers already present in the connection and the ones passed in to perform_request
#
def parse_headers!(headers, connection)
return unless headers

if connection.connection.headers
connection.connection.headers.merge!(headers)
else
connection.connection.headers = headers
end
end

# Builds and returns a connection
#
# @return [Connections::Connection]
Expand Down
2 changes: 1 addition & 1 deletion spec/elastic/transport/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@

it 'retries on 404 status the specified number of max_retries' do
expect do
client.transport.perform_request('GET', 'myindex/_doc/1?routing=FOOBARBAZ', {}, nil, nil, retry_on_failure: 5)
client.transport.perform_request('GET', 'myindex/_doc/42?routing=FOOBARBAZ', {}, nil, nil, retry_on_failure: 5)
end.to raise_exception(Elastic::Transport::Transport::Errors::NotFound)
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/elastic/transport/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
end

context 'when a User-Agent header is specified as a client option' do

let(:client) do
described_class.new(transport_class: Elastic::Transport::Transport::HTTP::Curb,
transport_options: { headers: { 'User-Agent' => 'testing' } })
Expand Down Expand Up @@ -1619,7 +1618,7 @@
context 'when an invalid url is specified' do
it 'raises an exception' do
expect {
client.perform_request('GET', 'myindex/_doc/1?routing=FOOBARBAZ')
client.perform_request('GET', 'myindex/_doc/42?routing=FOOBARBAZ')
}.to raise_exception(Elastic::Transport::Transport::Errors::NotFound)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/elastic/transport/opentelemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@

context 'sanitize in URL' do
let(:client) {
Elastic::Transport::Client.new(host: 'http://elastic:changeme@localhost:9250')
Elastic::Transport::Client.new(host: "http://elastic:changeme@#{ELASTICSEARCH_HOSTS.first}")
}

it 'sanitizes URL' do
Expand All @@ -334,7 +334,7 @@

span = exporter.finished_spans.find { |s| s.name == 'GET' }
expect(span.name).to eql('GET')
expect(span.attributes['url.full']).to match(/http:\/\/elastic:\*+@localhost:9250/)
expect(span.attributes['url.full']).to match(/http:\/\/elastic:\*+@localhost:/)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/transport_curb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Elastic::Transport::Transport::HTTP::FaradayTest < Minitest::Test
should "perform request with headers" do
@transport.connections.first.connection.expects(:put_data=).with('{"foo":"bar"}')
@transport.connections.first.connection.expects(:http).with(:POST).returns(stub_everything)
@transport.connections.first.connection.headers.expects(:merge!).with("Content-Type" => "application/x-ndjson")
@transport.connections.first.connection.headers.expects(:merge!).with({'Content-Type' => 'application/x-ndjson'})

@transport.perform_request 'POST', '/', {}, {:foo => 'bar'}, {"Content-Type" => "application/x-ndjson"}
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/transport_manticore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def common_headers
transport_options: { potatoes: 1 }
}

::Manticore::Client.expects(:new).with(potatoes: 1, ssl: {})
::Manticore::Client.expects(:new).with({ potatoes: 1, ssl: {} })
transport = Manticore.new(hosts: [{ host: 'foobar', port: 1234 }], options: options)
assert_equal(transport.options[:transport_options][:potatoes], 1)
end
Expand Down
Loading