Skip to content

Commit 5dab69a

Browse files
committed
v0.1.5 - Better headers encoding
1 parent b06f4da commit 5dab69a

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

lib/logtail-rack/http_request.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "logtail-rack/util/encoding"
2+
13
module Logtail
24
module Integrations
35
module Rack
@@ -24,7 +26,7 @@ def initialize(attributes)
2426
@service_name = attributes[:service_name]
2527

2628
if @headers
27-
@headers_json = @headers.to_json
29+
@headers_json = Util::Encoding.force_utf8_encoding(@headers).to_json
2830
end
2931
end
3032

lib/logtail-rack/http_response.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "logtail-rack/util/encoding"
2+
13
module Logtail
24
module Integrations
35
module Rack
@@ -19,7 +21,7 @@ def initialize(attributes)
1921
@duration_ms = attributes[:duration_ms]
2022

2123
if @headers
22-
@headers_json = @headers.to_json
24+
@headers_json = Util::Encoding.force_utf8_encoding(@headers).to_json
2325
end
2426
end
2527

lib/logtail-rack/util/encoding.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Logtail
2+
module Util
3+
class Encoding
4+
def self.force_utf8_encoding(data)
5+
if data.respond_to?(:force_encoding)
6+
data.dup.force_encoding('UTF-8')
7+
elsif data.respond_to?(:transform_values)
8+
data.transform_values { |val| Logtail::Util::Encoding.force_utf8_encoding(val) }
9+
else
10+
data
11+
end
12+
end
13+
end
14+
end
15+
end

lib/logtail-rack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Logtail
22
module Integrations
33
module Rack
4-
VERSION = "0.1.4"
4+
VERSION = "0.1.5"
55
end
66
end
77
end

0 commit comments

Comments
 (0)