http_logger 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/http_logger/configuration.rb +2 -0
- data/lib/http_logger/version.rb +1 -1
- data/lib/http_logger.rb +5 -1
- data/spec/http_logger_spec.rb +47 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 293c2066dfe071a200633e80d2ab28fa752ffa1f1cc9863fc1577d7544d36734
|
|
4
|
+
data.tar.gz: 6dfa4fa5c2d60141d5bf35c2f5501170f9cb26e5e63f0a14dc9bc21ed2d53b4b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e43e1a43adafc86c6c38aca71402340c5370afc74b793c6bff477ce14c1809b8040e0d6c207e0892ce558337eb96203b89a565d67fdd43b071ec6ca687b952e
|
|
7
|
+
data.tar.gz: e4d751fa35fce92194a0cb1058b989f870c391b12f6bfaf6fb3c0de2495f134edfc29ab779378efd60cd8c86f004e54993d98a5afd1bed072e782096d66bd9fc
|
data/README.md
CHANGED
|
@@ -44,6 +44,11 @@ HttpLogger.configure do |c|
|
|
|
44
44
|
|
|
45
45
|
# Change default truncate limit. Default: 5000
|
|
46
46
|
c.collapse_body_limit = 5000
|
|
47
|
+
|
|
48
|
+
# Header names whose values are logged as <filtered>, case-insensitive.
|
|
49
|
+
# Default: ["Authorization"]. Setting it replaces the default rather than
|
|
50
|
+
# adding to it; an empty list logs every header in full.
|
|
51
|
+
c.filtered_headers = %w[Authorization X-Api-Key]
|
|
47
52
|
end
|
|
48
53
|
```
|
|
49
54
|
|
|
@@ -8,6 +8,7 @@ class HttpLogger
|
|
|
8
8
|
attr_accessor :colorize
|
|
9
9
|
attr_accessor :ignore
|
|
10
10
|
attr_accessor :level
|
|
11
|
+
attr_accessor :filtered_headers
|
|
11
12
|
|
|
12
13
|
def initialize
|
|
13
14
|
reset
|
|
@@ -21,6 +22,7 @@ class HttpLogger
|
|
|
21
22
|
self.collapse_body_limit = 5000
|
|
22
23
|
self.ignore = []
|
|
23
24
|
self.level = :debug
|
|
25
|
+
self.filtered_headers = ['Authorization']
|
|
24
26
|
end
|
|
25
27
|
end
|
|
26
28
|
end
|
data/lib/http_logger/version.rb
CHANGED
data/lib/http_logger.rb
CHANGED
|
@@ -94,10 +94,14 @@ class HttpLogger
|
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
def log_header(type, name, value)
|
|
97
|
-
value = "<filtered>" if name
|
|
97
|
+
value = "<filtered>" if filtered_header?(name)
|
|
98
98
|
log("HTTP #{type} header", "#{name}: #{value}")
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
+
def filtered_header?(name)
|
|
102
|
+
Array(configuration.filtered_headers).any? { |header| header.to_s.casecmp?(name.to_s) }
|
|
103
|
+
end
|
|
104
|
+
|
|
101
105
|
HTTP_METHODS_WITH_BODY = Set.new(%w(POST PUT GET PATCH))
|
|
102
106
|
|
|
103
107
|
def log_request_body(request, request_body = nil)
|
data/spec/http_logger_spec.rb
CHANGED
|
@@ -240,4 +240,51 @@ describe HttpLogger do
|
|
|
240
240
|
after(:each) do
|
|
241
241
|
HttpLogger.configuration.reset
|
|
242
242
|
end
|
|
243
|
+
|
|
244
|
+
describe "filtered_headers" do
|
|
245
|
+
before(:each) do
|
|
246
|
+
HttpLogger.configuration.log_headers = true
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
let(:request_headers) do
|
|
250
|
+
{'Authorization' => "Bearer secret", 'X-Api-Key' => "key123"}
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
it "filters Authorization by default and leaves other headers alone" do
|
|
254
|
+
subject.should include("Authorization: <filtered>")
|
|
255
|
+
subject.should include("X-Api-Key: key123")
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
context "with a custom list" do
|
|
259
|
+
before(:each) do
|
|
260
|
+
HttpLogger.configuration.filtered_headers = %w[x-api-key]
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it "matches case-insensitively and no longer filters Authorization" do
|
|
264
|
+
subject.should include("X-Api-Key: <filtered>")
|
|
265
|
+
subject.should include("Authorization: Bearer secret")
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
context "with an empty list" do
|
|
270
|
+
before(:each) do
|
|
271
|
+
HttpLogger.configuration.filtered_headers = []
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
it "logs every header in full" do
|
|
275
|
+
subject.should include("Authorization: Bearer secret")
|
|
276
|
+
subject.should include("X-Api-Key: key123")
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
context "with response headers" do
|
|
281
|
+
let(:response_headers) { {'Set-Cookie' => "session=abc"} }
|
|
282
|
+
|
|
283
|
+
before(:each) do
|
|
284
|
+
HttpLogger.configuration.filtered_headers = %w[Authorization Set-Cookie]
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
it { should include("Set-Cookie: <filtered>") }
|
|
288
|
+
end
|
|
289
|
+
end
|
|
243
290
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: http_logger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bogdan Gusiev
|
|
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
172
172
|
- !ruby/object:Gem::Version
|
|
173
173
|
version: '0'
|
|
174
174
|
requirements: []
|
|
175
|
-
rubygems_version:
|
|
175
|
+
rubygems_version: 4.0.3
|
|
176
176
|
specification_version: 4
|
|
177
177
|
summary: Log your http api calls just like SQL queries
|
|
178
178
|
test_files: []
|