Skip to content

Can not overrride user-agent header with Manticore adapter #1684

@kares

Description

@kares

Seems adding a transport_options = { :headers => { "User-Agent" => "Custom UA" } } does not work and the library always uses it's UA default value, sample reproducer:

require 'webrick' start_wait = Queue.new Thread.start do server = WEBrick::HTTPServer.new :Port => 9201, :DocumentRoot => ".", :StartCallback => Proc.new { start_wait.push :started } server.mount_proc '/' do |req, res| puts "\n" puts "user-agent: #{req.header['user-agent']}" puts "authorization: #{req.header['authorization']}" res.body = '''  {  "name": "dummy",  "cluster_name": "dummy-cluster",  "cluster_uuid": "ABCDEFGH",  "version": {  "number": "7.13.1",  "build_flavor": "default",  "build_type": "docker",  "build_hash": "9a7758028e4ea59bcab41c12004603c5a7dd84a9",  "build_date": "2021-05-28T17:40:59.346932922Z",  "build_snapshot": false,  "lucene_version": "8.8.2",  "minimum_wire_compatibility_version": "6.8.0",  "minimum_index_compatibility_version": "6.0.0-beta1"  },  "tagline": "You Know, for Search"  }  ''' res.status = 200 res['Content-Type'] = 'application/json' end server.start end start_wait.pop # blocks until the server is up gem 'elasticsearch', ENV['ELASTICSEARCH_VERSION'] if ENV['ELASTICSEARCH_VERSION'] require "elasticsearch" require "elasticsearch/transport/transport/http/manticore" puts "Manticore::VERSION: #{Manticore::VERSION}" es_client_version = Gem.loaded_specs['elasticsearch-transport'].version puts "elasticsearch-transport version: #{es_client_version}" transport_options = { :headers => { "User-Agent" => "Custom UA", 'Authorization' => 'Auth Header' } } client = ::Elasticsearch::Client.new(hosts: ['localhost:9201'], transport_options: transport_options, transport_class: ::Elasticsearch::Transport::Transport::HTTP::Manticore) client.ping

NOTE: Logstash filter and input ES plugins have a variation of using lower-case 'user-agent' to set the header the end result is the same.

prints:

[2022-02-09 08:24:48] INFO WEBrick 1.7.0 [2022-02-09 08:24:48] INFO ruby 2.5.8 (2021-11-02) [java] [2022-02-09 08:24:48] INFO WEBrick::HTTPServer#start: pid=4015534 port=9201 Manticore::VERSION: 0.8.0 elasticsearch-transport version: 7.17.0 user-agent: ["elasticsearch-ruby/7.17.0 (RUBY_VERSION: 9.2.20.0; linux x86_64; Manticore 0.8.0)"] authorization: ["Auth Header"] 127.0.0.1 - - [09/Feb/2022:08:24:53 CET] "GET / HTTP/1.1" 200 810 - -> / user-agent: ["elasticsearch-ruby/7.17.0 (RUBY_VERSION: 9.2.20.0; linux x86_64; Manticore 0.8.0)"] authorization: ["Auth Header"] 127.0.0.1 - - [09/Feb/2022:08:24:53 CET] "HEAD / HTTP/1.1" 200 0 - -> / 

The header was working up till the plugins were using ES < 7.16 due a patch in place (the patch was introduced due a previous issue of not sending header at all).

Tested the above script with every minor down to 7.10 (ELASTICSEARCH_VERSION=7.10.1 jruby repro.rb) the header override never worked in any of the versions I tried:

[2022-02-09 08:33:51] INFO WEBrick 1.7.0 [2022-02-09 08:33:51] INFO ruby 2.5.8 (2021-11-02) [java] [2022-02-09 08:33:52] INFO WEBrick::HTTPServer#start: pid=4027356 port=9201 Manticore::VERSION: 0.8.0 elasticsearch-transport version: 7.10.1 user-agent: ["elasticsearch-ruby/7.10.1 (RUBY_VERSION: 9.2.20.0; linux x86_64; Manticore 0.8.0)"] authorization: [] 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions