|
73 | 73 |
|
74 | 74 | expect_any_instance_of(Faraday::Connection) |
75 | 75 | .to receive(:run_request) |
76 | | - .with(:get, 'http://localhost:9200/_search', nil, connection_headers) { OpenStruct.new(body: '') } |
| 76 | + .with(:get, 'http://localhost:9200/_search', nil, connection_headers) { OpenStruct.new(body: '') } |
77 | 77 | client.search |
78 | 78 | end |
79 | 79 | end |
80 | 80 |
|
81 | 81 | context 'when content-type header is changed' do |
82 | 82 | let!(:client) do |
83 | | - described_class.new( |
84 | | - host: 'http://localhost:9200', |
85 | | - transport_options: { headers: instance_headers } |
86 | | - ).tap do |client| |
| 83 | + described_class.new(transport_options: { headers: instance_headers }).tap do |client| |
87 | 84 | client.instance_variable_set('@verified', true) |
88 | 85 | end |
89 | 86 | end |
| 87 | + |
90 | 88 | let(:instance_headers) do |
91 | 89 | { content_type: 'application/json' } |
92 | 90 | end |
|
98 | 96 |
|
99 | 97 | expect_any_instance_of(Faraday::Connection) |
100 | 98 | .to receive(:run_request) |
101 | | - .with(:get, 'http://localhost:9200/_search', nil, connection_headers) { OpenStruct.new(body: '') } |
| 99 | + .with(:get, 'http://localhost:9200/_search', nil, connection_headers) { OpenStruct.new(body: '') } |
| 100 | + client.search |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | + context 'when Content-Type header is used' do |
| 105 | + let(:client) do |
| 106 | + described_class.new(transport_options: { headers: instance_headers }).tap do |client| |
| 107 | + client.instance_variable_set('@verified', true) |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | + let(:instance_headers) do |
| 112 | + { 'Content-Type' => 'application/text' } |
| 113 | + end |
| 114 | + |
| 115 | + it 'performs the request with the header' do |
| 116 | + connection_headers = client.transport.connections.connections.first.connection.headers |
| 117 | + expect(connection_headers['Accept']).to eq 'application/vnd.elasticsearch+json; compatible-with=9' |
| 118 | + expect(connection_headers['Content-Type']).to eq 'application/text' |
| 119 | + |
| 120 | + expect_any_instance_of(Faraday::Connection) |
| 121 | + .to receive(:run_request) |
| 122 | + .with(:get, 'http://localhost:9200/_search', nil, connection_headers) { OpenStruct.new(body: '') } |
102 | 123 | client.search |
103 | 124 | end |
104 | 125 | end |
105 | 126 |
|
| 127 | + if defined?(JRUBY_VERSION) |
| 128 | + context 'Using Manticore with JRuby' do |
| 129 | + let(:client) do |
| 130 | + require 'elastic/transport/transport/http/manticore' |
| 131 | + described_class.new( |
| 132 | + transport_class: Elastic::Transport::Transport::HTTP::Manticore, |
| 133 | + transport_options: { headers: instance_headers } |
| 134 | + ).tap do |client| |
| 135 | + client.instance_variable_set('@verified', true) |
| 136 | + end |
| 137 | + end |
| 138 | + |
| 139 | + context 'when Content-Type header is used' do |
| 140 | + let(:instance_headers) do |
| 141 | + { 'Content-Type' => 'application/text' } |
| 142 | + end |
| 143 | + |
| 144 | + it 'does not duplicate content-type the header' do |
| 145 | + connection_headers = client.transport.connections.connections.first.connection.instance_variable_get('@options')[:headers] |
| 146 | + expect(connection_headers['accept']).to eq 'application/vnd.elasticsearch+json; compatible-with=9' |
| 147 | + expect(connection_headers['content-type']).to be nil |
| 148 | + expect(connection_headers.fetch('Content-Type')).to eq 'application/text' |
| 149 | + |
| 150 | + expect_any_instance_of(Manticore::Client) |
| 151 | + .to receive(:get).with( |
| 152 | + 'http://localhost:9200/_search', |
| 153 | + { headers: connection_headers } |
| 154 | + ) { OpenStruct.new(body: '') } |
| 155 | + client.search |
| 156 | + end |
| 157 | + |
| 158 | + context 'when content-type header is used' do |
| 159 | + let(:instance_headers) do |
| 160 | + { 'content-type' => 'application/text' } |
| 161 | + end |
| 162 | + |
| 163 | + it 'does not duplicate Content-Type the header' do |
| 164 | + connection_headers = client.transport.connections.connections.first.connection.instance_variable_get('@options')[:headers] |
| 165 | + expect(connection_headers['accept']).to eq 'application/vnd.elasticsearch+json; compatible-with=9' |
| 166 | + expect(connection_headers['content-type']).to be nil |
| 167 | + expect(connection_headers.fetch('Content-Type')).to eq 'application/text' |
| 168 | + |
| 169 | + expect_any_instance_of(Manticore::Client) |
| 170 | + .to receive(:get).with( |
| 171 | + 'http://localhost:9200/_search', |
| 172 | + { headers: connection_headers } |
| 173 | + ) { OpenStruct.new(body: '') } |
| 174 | + client.search |
| 175 | + end |
| 176 | + end |
| 177 | + end |
| 178 | + end |
| 179 | + end |
| 180 | + |
106 | 181 | context 'when no header is set, uses v9 content-type and accept' do |
107 | 182 | let!(:client) do |
108 | 183 | described_class.new(host: 'http://localhost:9200').tap do |client| |
|
117 | 192 |
|
118 | 193 | expect_any_instance_of(Faraday::Connection) |
119 | 194 | .to receive(:run_request) |
120 | | - .with(:get, 'http://localhost:9200/_search', nil, expected_headers) { OpenStruct.new(body: '') } |
| 195 | + .with(:get, 'http://localhost:9200/_search', nil, expected_headers) { OpenStruct.new(body: '') } |
121 | 196 | client.search |
122 | 197 | end |
123 | 198 | end |
|
0 commit comments