lib/semantic_logger/appender/http.rb in semantic_logger-4.13.0 vs lib/semantic_logger/appender/http.rb in semantic_logger-4.14.0
- old
+ new
@@ -46,10 +46,15 @@
# Default: nil ( do not use basic auth )
#
# password: [String]
# Password for basic Authentication.
#
+ # header: [Hash]
+ # Custom HTTP headers to send with each request.
+ # Default: {} ( do not send any custom headers)
+ # Example: {"Authorization" => "Bearer BEARER_TOKEN"}
+ #
# compress: [true|false]
# Whether to compress the JSON string with GZip.
# Default: false
#
# ssl: [Hash]
@@ -93,10 +98,11 @@
def initialize(url:,
compress: false,
ssl: {},
username: nil,
password: nil,
+ header: {},
proxy_url: :ENV,
open_timeout: 2.0,
read_timeout: 1.0,
continue_timeout: 1.0,
**args,
@@ -116,11 +122,11 @@
@header = {
"Accept" => "application/json",
"Content-Type" => "application/json",
"Connection" => "keep-alive",
"Keep-Alive" => "300"
- }
+ }.merge(header)
@header["Content-Encoding"] = "gzip" if @compress
uri = URI.parse(@url)
@server = uri.host
unless @server
@@ -224,10 +230,10 @@
if body
request.body = compress ? compress_data(body) : body
end
request.basic_auth(@username, @password) if @username
response = @http.request(request)
- if response.code == "200" || response.code == "201"
+ if response.is_a?(Net::HTTPSuccess)
true
else
# Failures are logged to the global semantic logger failsafe logger (Usually stderr or file)
logger.error("Bad HTTP response from: #{url} code: #{response.code}, #{response.body}")
false