Skip to content

Commit

Permalink
Refactors apply_headers in base and manticore
Browse files Browse the repository at this point in the history
When passing in an object to the initializer, the apply_headers would mutate this object and in
certain conditions, this would raise "RuntimeError" in JRuby 9.3 and "ConcurrencyError" in JRuby
9.4. This update clones the options object instead.
  • Loading branch information
picandocodigo committed Jul 5, 2023
1 parent 09ba4b4 commit feb7ca0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/elastic/transport/transport/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def use_compression?
end

def apply_headers(client, options)
headers = options[:headers] || {}
headers = options[:headers].clone || {}
headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || user_agent_header(client)
client.headers[ACCEPT_ENCODING] = GZIP if use_compression?
Expand Down
2 changes: 1 addition & 1 deletion lib/elastic/transport/transport/http/manticore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def host_unreachable_exceptions
private

def apply_headers(options)
headers = options[:headers] || options.dig(:transport_options, :headers) || {}
headers = options[:headers].clone || options.dig(:transport_options, :headers).clone || {}
headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || find_value(@request_options[:headers], USER_AGENT_REGEX) || user_agent_header
headers[ACCEPT_ENCODING] = GZIP if use_compression?
Expand Down

0 comments on commit feb7ca0

Please sign in to comment.