Enhancement: Added header support for UserAgent requests.

This commit is contained in:
Thorsten Eckel 2020-09-30 11:37:57 +02:00
parent e65c8b1399
commit ffe5948699

View file

@ -48,7 +48,10 @@ returns
http = get_http(uri, options)
# prepare request
request = Net::HTTP::Get.new(uri, { 'User-Agent' => 'Zammad User Agent' })
request = Net::HTTP::Get.new(uri)
# set headers
request = set_headers(request, options)
# http basic auth (if needed)
request = set_basic_auth(request, options)
@ -104,7 +107,10 @@ returns
http = get_http(uri, options)
# prepare request
request = Net::HTTP::Post.new(uri, { 'User-Agent' => 'Zammad User Agent' })
request = Net::HTTP::Post.new(uri)
# set headers
request = set_headers(request, options)
# set params
request = set_params(request, params, options)
@ -159,7 +165,10 @@ returns
http = get_http(uri, options)
# prepare request
request = Net::HTTP::Put.new(uri, { 'User-Agent' => 'Zammad User Agent' })
request = Net::HTTP::Put.new(uri)
# set headers
request = set_headers(request, options)
# set params
request = set_params(request, params, options)
@ -210,7 +219,10 @@ returns
http = get_http(uri, options)
# prepare request
request = Net::HTTP::Delete.new(uri, { 'User-Agent' => 'Zammad User Agent' })
request = Net::HTTP::Delete.new(uri)
# set headers
request = set_headers(request, options)
# http basic auth (if needed)
request = set_basic_auth(request, options)
@ -334,6 +346,17 @@ returns
request
end
def self.set_headers(request, options)
defaults = { 'User-Agent' => 'Zammad User Agent' }
headers = defaults.merge(options.fetch(:headers, {}))
headers.each do |header, value|
request[header] = value
end
request
end
def self.log(url, request, response, options)
return if !options[:log]