Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

Commit 1df602f

Browse files
committed
Ensure the new content_length field for HTTP request and response events are an integer.
1 parent c1fa671 commit 1df602f

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Ensure the new `content_length` field for HTTP request and response events are an integer.
13+
1014
## [2.5.0] - 2017-10-27
1115

1216
### Changed

lib/timber/events/http_request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class HTTPRequest < Timber::Event
1414

1515
def initialize(attributes)
1616
@body = attributes[:body] && Util::HTTPEvent.normalize_body(attributes[:body])
17-
@content_length = attributes[:content_length]
17+
@content_length = Timber::Util::Object.try(attributes[:content_length], :to_i)
1818
@headers = Util::HTTPEvent.normalize_headers(attributes[:headers])
1919
@host = attributes[:host]
2020
@method = Util::HTTPEvent.normalize_method(attributes[:method]) || raise(ArgumentError.new(":method is required"))

lib/timber/events/http_response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class HTTPResponse < Timber::Event
1313

1414
def initialize(attributes)
1515
@body = attributes[:body] && Util::HTTPEvent.normalize_body(attributes[:body])
16-
@content_length = attributes[:content_length]
16+
@content_length = Timber::Util::Object.try(attributes[:content_length], :to_i)
1717
@headers = Util::HTTPEvent.normalize_headers(attributes[:headers])
1818
@http_context = attributes[:http_context]
1919
@request_id = attributes[:request_id]

spec/timber/events/http_request_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
describe Timber::Events::HTTPRequest, :rails_23 => true do
66
describe ".initialize" do
7+
it "should coerce content_length into an integer" do
8+
event = described_class.new(:method => 'GET', :content_length => "123")
9+
expect(event.content_length).to eq(123)
10+
end
11+
712
context "with a header filters" do
813
around(:each) do |example|
914
old_http_header_filters = Timber::Config.instance.http_header_filters
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# encoding: UTF-8
2+
3+
require "spec_helper"
4+
5+
describe Timber::Events::HTTPResponse, :rails_23 => true do
6+
describe ".initialize" do
7+
it "should coerce content_length into an integer" do
8+
event = described_class.new(:content_length => "123", :status => 200, :time_ms => 1)
9+
expect(event.content_length).to eq(123)
10+
end
11+
end
12+
end

0 commit comments

Comments
 (0)