Skip to content

Commit b06f4da

Browse files
Force numeric content type value (#3)
* Force content length to be an integer * Force also response content length to be an integer * Bump version number * Support older versions of ruby * Extract code to a private function
1 parent ae131b3 commit b06f4da

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/logtail-rack/http_events.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def call(env)
142142

143143
Config.instance.logger.info do
144144
http_context = CurrentContext.fetch(:http)
145-
content_length = headers[CONTENT_LENGTH_KEY]
145+
content_length = safe_to_i(headers[CONTENT_LENGTH_KEY])
146146
duration_ms = (Time.now - start) * 1000.0
147147

148148
http_response = HTTPResponse.new(
@@ -180,7 +180,7 @@ def call(env)
180180
event_body = capture_request_body? ? request.body_content : nil
181181
http_request = HTTPRequest.new(
182182
body: event_body,
183-
content_length: request.content_length,
183+
content_length: safe_to_i(request.content_length),
184184
headers: request.headers,
185185
host: force_encoding(request.host),
186186
method: request.request_method,
@@ -217,7 +217,7 @@ def call(env)
217217

218218
Config.instance.logger.info do
219219
event_body = capture_response_body? ? body : nil
220-
content_length = headers[CONTENT_LENGTH_KEY]
220+
content_length = safe_to_i(headers[CONTENT_LENGTH_KEY])
221221
duration_ms = (Time.now - start) * 1000.0
222222

223223
http_response = HTTPResponse.new(
@@ -272,6 +272,10 @@ def silenced?(env, request)
272272
end
273273
end
274274

275+
def safe_to_i(val)
276+
val.nil? ? nil : val.to_i
277+
end
278+
275279
def force_encoding(value)
276280
if value.respond_to?(:force_encoding)
277281
value.dup.force_encoding('UTF-8')

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.3"
4+
VERSION = "0.1.4"
55
end
66
end
77
end

0 commit comments

Comments
 (0)