diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000..37c2961c2 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.7.2 diff --git a/lib/twilio-ruby/base/client_base.rb b/lib/twilio-ruby/base/client_base.rb index 8ddc83875..b4619c575 100644 --- a/lib/twilio-ruby/base/client_base.rb +++ b/lib/twilio-ruby/base/client_base.rb @@ -27,10 +27,9 @@ def initialize(username = nil, password = nil, account_sid = nil, region = nil, ## # Makes a request to the Twilio API using the configured http client # Authentication information is automatically added if none is provided - # rubocop:disable Lint/ShadowedArgument def request(host, port, method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) # rubocop:disable Metrics/MethodLength auth ||= @auth - headers = generate_headers(method) + headers = generate_headers(method, headers) uri = build_uri(uri) if @logger @@ -68,7 +67,6 @@ def request(host, port, method, uri, params = {}, data = {}, headers = {}, auth response end - # rubocop:enable Lint/ShadowedArgument ## # Build the final request uri @@ -105,9 +103,8 @@ def validate_ssl_certificate raise RestError.new 'Unexpected response from certificate endpoint', response end - def generate_headers(method) + def generate_headers(method, headers) ruby_config = RbConfig::CONFIG - headers = {} headers['User-Agent'] = "twilio-ruby/#{Twilio::VERSION} (#{ruby_config['host_os']} #{ruby_config['host_cpu']}) Ruby/#{RUBY_VERSION}" headers['Accept-Charset'] = 'utf-8' diff --git a/spec/rest/client_spec.rb b/spec/rest/client_spec.rb index 7706b03ed..fa2459ca5 100644 --- a/spec/rest/client_spec.rb +++ b/spec/rest/client_spec.rb @@ -221,7 +221,7 @@ def initialize(client) it 'use default user agent format' do @client.request('host', 'port', 'GET', 'https://api.twilio.com') - expect(@client.http_client.last_request.headers['User-Agent']).to match %r{^twilio-ruby/[0-9.]+(-rc\.[0-9]+)?\s\([\w-]+\s\w+\)\sRuby/[^\s]+$} + expect(@client.http_client.last_request.headers['User-Agent']).to match %r{^twilio-ruby/[0-9.]+(-rc\.[0-9]+)?\s\([\w.-]+\s\w+\)\sRuby/[^\s]+$} end it 'add user agent extensions' do @@ -231,5 +231,11 @@ def initialize(client) actual_extensions = @client.http_client.last_request.headers['User-Agent'].split(/ /).last(extensions.size) expect(actual_extensions).to match_array(extensions) end + + it 'preserve headers passed' do + headers = Twilio::Values.of({ 'X-Twilio-Webhook-Enabled' => 'true' }) + @client.request('host', 'port', 'GET', 'https://api.twilio.com', nil, nil, headers) + expect(@client.http_client.last_request.headers['X-Twilio-Webhook-Enabled']).to eq('true') + end end end