http_logger 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -7
- data/Gemfile.lock +55 -70
- data/Rakefile +3 -14
- data/Readme.md +25 -8
- data/http_logger.gemspec +12 -30
- data/lib/http_logger.rb +67 -54
- data/spec/http_logger_spec.rb +37 -23
- data/spec/spec_helper.rb +1 -1
- metadata +21 -9
- data/VERSION +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5e25ba1ebb81a4e187ff3a60481249bd5b9d2795c02ff5470bd635f6b0e4f79
|
4
|
+
data.tar.gz: 99d08eec0c1be45a9db701d2190c7274dbae4ed998d757c7fa83949975d33dcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5adf4d6151c4b382ab63010be5468638ac4697eacec5ba2872676dca44e1dc6218b4683db11d734e0e5a46e480d78293f7079307bd4e0a26a9f21a38702dd58
|
7
|
+
data.tar.gz: 8437f529565c4e73969dc1ba17f7808b3ccaa03319064057a7254f0d8489cd99e718d832e87e37ca0d2a3052907730bf2a7309bfb2aba3d32be1c65909b9da49
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,86 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
http_logger (1.0.0)
|
5
|
+
|
1
6
|
GEM
|
2
7
|
remote: http://rubygems.org/
|
3
8
|
specs:
|
4
|
-
addressable (2.
|
5
|
-
|
6
|
-
|
7
|
-
crack (0.4.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
multi_xml (0.6.0)
|
41
|
-
multipart-post (2.1.1)
|
42
|
-
nokogiri (1.10.7)
|
43
|
-
mini_portile2 (~> 2.4.0)
|
44
|
-
oauth2 (1.4.2)
|
45
|
-
faraday (>= 0.8, < 2.0)
|
46
|
-
jwt (>= 1.0, < 3.0)
|
47
|
-
multi_json (~> 1.3)
|
48
|
-
multi_xml (~> 0.5)
|
49
|
-
rack (>= 1.2, < 3)
|
50
|
-
psych (3.1.0)
|
51
|
-
rack (2.1.1)
|
52
|
-
rake (13.0.1)
|
53
|
-
rdoc (6.2.1)
|
54
|
-
rspec (3.9.0)
|
55
|
-
rspec-core (~> 3.9.0)
|
56
|
-
rspec-expectations (~> 3.9.0)
|
57
|
-
rspec-mocks (~> 3.9.0)
|
58
|
-
rspec-core (3.9.1)
|
59
|
-
rspec-support (~> 3.9.1)
|
60
|
-
rspec-expectations (3.9.0)
|
9
|
+
addressable (2.8.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
|
+
bump (0.10.0)
|
12
|
+
crack (0.4.5)
|
13
|
+
rexml
|
14
|
+
date (3.4.1)
|
15
|
+
debug (1.10.0)
|
16
|
+
irb (~> 1.10)
|
17
|
+
reline (>= 0.3.8)
|
18
|
+
diff-lcs (1.6.0)
|
19
|
+
hashdiff (1.0.1)
|
20
|
+
io-console (0.8.0)
|
21
|
+
irb (1.15.1)
|
22
|
+
pp (>= 0.6.0)
|
23
|
+
rdoc (>= 4.0.0)
|
24
|
+
reline (>= 0.4.2)
|
25
|
+
pp (0.6.2)
|
26
|
+
prettyprint
|
27
|
+
prettyprint (0.2.0)
|
28
|
+
psych (5.2.3)
|
29
|
+
date
|
30
|
+
stringio
|
31
|
+
public_suffix (4.0.6)
|
32
|
+
rake (13.0.6)
|
33
|
+
rdoc (6.12.0)
|
34
|
+
psych (>= 4.0.0)
|
35
|
+
reline (0.6.0)
|
36
|
+
io-console (~> 0.5)
|
37
|
+
rexml (3.2.5)
|
38
|
+
rspec (3.13.0)
|
39
|
+
rspec-core (~> 3.13.0)
|
40
|
+
rspec-expectations (~> 3.13.0)
|
41
|
+
rspec-mocks (~> 3.13.0)
|
42
|
+
rspec-core (3.13.3)
|
43
|
+
rspec-support (~> 3.13.0)
|
44
|
+
rspec-expectations (3.13.3)
|
61
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.
|
63
|
-
rspec-mocks (3.
|
46
|
+
rspec-support (~> 3.13.0)
|
47
|
+
rspec-mocks (3.13.2)
|
64
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
-
rspec-support (~> 3.
|
66
|
-
rspec-support (3.
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
webmock (3.8.0)
|
71
|
-
addressable (>= 2.3.6)
|
49
|
+
rspec-support (~> 3.13.0)
|
50
|
+
rspec-support (3.13.2)
|
51
|
+
stringio (3.1.4)
|
52
|
+
webmock (3.14.0)
|
53
|
+
addressable (>= 2.8.0)
|
72
54
|
crack (>= 0.3.2)
|
73
55
|
hashdiff (>= 0.4.0, < 2.0.0)
|
74
56
|
|
75
57
|
PLATFORMS
|
76
|
-
|
58
|
+
arm64-darwin-23
|
59
|
+
x86_64-darwin-19
|
77
60
|
|
78
61
|
DEPENDENCIES
|
62
|
+
bump
|
79
63
|
bundler
|
80
|
-
|
81
|
-
|
64
|
+
debug
|
65
|
+
http_logger!
|
66
|
+
rake
|
82
67
|
rspec
|
83
68
|
webmock
|
84
69
|
|
85
70
|
BUNDLED WITH
|
86
|
-
2.
|
71
|
+
2.2.22
|
data/Rakefile
CHANGED
@@ -9,24 +9,13 @@ rescue Bundler::BundlerError => e
|
|
9
9
|
$stderr.puts "Run `bundle install` to install missing gems"
|
10
10
|
exit e.status_code
|
11
11
|
end
|
12
|
-
require 'rake'
|
13
12
|
|
14
|
-
require '
|
15
|
-
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "http_logger"
|
18
|
-
gem.homepage = "http://github.com/railsware/http_logger"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{Log your http api calls just like SQL queries}
|
21
|
-
gem.description = %Q{This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file}
|
22
|
-
gem.email = "agresso@gmail.com"
|
23
|
-
gem.authors = ["Bogdan Gusiev"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
13
|
+
require 'rake'
|
14
|
+
require 'bundler/gem_tasks'
|
27
15
|
|
28
16
|
require 'rspec/core'
|
29
17
|
require 'rspec/core/rake_task'
|
18
|
+
|
30
19
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
20
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
21
|
end
|
data/Readme.md
CHANGED
@@ -20,14 +20,31 @@ gem install http_logger
|
|
20
20
|
``` ruby
|
21
21
|
require 'http_logger'
|
22
22
|
|
23
|
-
HttpLogger.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
HttpLogger.configure do |c|
|
24
|
+
# defaults to Rails.logger if Rails is defined
|
25
|
+
c.logger = Logger.new(LOGFILE)
|
26
|
+
|
27
|
+
# Default: true
|
28
|
+
c.colorize = true
|
29
|
+
|
30
|
+
# Ignore patterns (e.g., URLs to ignore)
|
31
|
+
c.ignore = [/newrelic\.com/]
|
32
|
+
|
33
|
+
# Default: false
|
34
|
+
c.log_headers = false
|
35
|
+
|
36
|
+
# Default: true
|
37
|
+
c.log_request_body = false
|
38
|
+
|
39
|
+
# Default: true
|
40
|
+
c.log_response_body = false
|
41
|
+
|
42
|
+
# Desired log level as a symbol. Default: :debug
|
43
|
+
c.level = :info
|
44
|
+
|
45
|
+
# Change default truncate limit. Default: 5000
|
46
|
+
c.collapse_body_limit = 5000
|
47
|
+
end
|
31
48
|
```
|
32
49
|
|
33
50
|
## Alternative
|
data/http_logger.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "http_logger/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "http_logger".freeze
|
9
|
-
s.version =
|
9
|
+
s.version = HttpLogger::VERSION
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
|
|
25
25
|
"LICENSE.txt",
|
26
26
|
"Rakefile",
|
27
27
|
"Readme.md",
|
28
|
-
"VERSION",
|
29
28
|
"http_logger.gemspec",
|
30
29
|
"lib/http_logger.rb",
|
31
30
|
"screenshots/hoptoad.png",
|
@@ -39,28 +38,11 @@ Gem::Specification.new do |s|
|
|
39
38
|
s.rubygems_version = "2.7.8".freeze
|
40
39
|
s.summary = "Log your http api calls just like SQL queries".freeze
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
|
49
|
-
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
50
|
-
s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
|
51
|
-
else
|
52
|
-
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
53
|
-
s.add_dependency(%q<webmock>.freeze, [">= 0"])
|
54
|
-
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
55
|
-
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
56
|
-
s.add_dependency(%q<jeweler>.freeze, [">= 0"])
|
57
|
-
end
|
58
|
-
else
|
59
|
-
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
60
|
-
s.add_dependency(%q<webmock>.freeze, [">= 0"])
|
61
|
-
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
62
|
-
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
63
|
-
s.add_dependency(%q<jeweler>.freeze, [">= 0"])
|
64
|
-
end
|
41
|
+
s.add_development_dependency(%q<debug>.freeze, [">= 0"])
|
42
|
+
s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
|
43
|
+
s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
|
44
|
+
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<bump>.freeze, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
65
47
|
end
|
66
48
|
|
data/lib/http_logger.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'uri'
|
3
3
|
require 'set'
|
4
|
+
require 'http_logger/configuration'
|
4
5
|
|
5
6
|
# Usage:
|
6
7
|
#
|
@@ -8,8 +9,8 @@ require 'set'
|
|
8
9
|
#
|
9
10
|
# == Setup logger
|
10
11
|
#
|
11
|
-
# HttpLogger.logger = Logger.new('/tmp/all.log')
|
12
|
-
# HttpLogger.log_headers = true
|
12
|
+
# HttpLogger.configuration.logger = Logger.new('/tmp/all.log')
|
13
|
+
# HttpLogger.configuration.log_headers = true
|
13
14
|
#
|
14
15
|
# == Do request
|
15
16
|
#
|
@@ -22,24 +23,16 @@ require 'set'
|
|
22
23
|
#
|
23
24
|
# cat /tmp/all.log
|
24
25
|
class HttpLogger
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
self.log_headers = false
|
37
|
-
self.log_request_body = true
|
38
|
-
self.log_response_body = true
|
39
|
-
self.colorize = true
|
40
|
-
self.collapse_body_limit = 5000
|
41
|
-
self.ignore = []
|
42
|
-
self.level = :debug
|
26
|
+
AUTHORIZATION_HEADER = 'Authorization'
|
27
|
+
|
28
|
+
def self.configuration
|
29
|
+
@configuration ||= Configuration.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.configure(&block)
|
33
|
+
block.call(configuration)
|
34
|
+
end
|
35
|
+
|
43
36
|
|
44
37
|
def self.perform(*args, &block)
|
45
38
|
instance.perform(*args, &block)
|
@@ -49,10 +42,6 @@ class HttpLogger
|
|
49
42
|
@instance ||= HttpLogger.new
|
50
43
|
end
|
51
44
|
|
52
|
-
def self.deprecate_config(option)
|
53
|
-
warn "Net::HTTP.#{option} is deprecated. Use HttpLogger.#{option} instead."
|
54
|
-
end
|
55
|
-
|
56
45
|
def perform(http, request, request_body)
|
57
46
|
start_time = Time.now
|
58
47
|
response = yield
|
@@ -64,13 +53,21 @@ class HttpLogger
|
|
64
53
|
if defined?(response) && response
|
65
54
|
log_response_code(response)
|
66
55
|
log_response_headers(response)
|
67
|
-
log_response_body(response.body)
|
56
|
+
log_response_body(response.body, binary_response?(response))
|
68
57
|
end
|
69
58
|
end
|
70
59
|
end
|
71
60
|
|
72
61
|
protected
|
73
62
|
|
63
|
+
def binary_response?(response)
|
64
|
+
content_type = response['Content-Type']
|
65
|
+
return false if content_type.nil?
|
66
|
+
|
67
|
+
!content_type.start_with?('text/', 'application/json', 'application/xml', 'application/javascript', 'application/x-www-form-urlencoded', 'application/xhtml+xml', 'application/rss+xml', 'application/atom+xml', 'application/svg+xml', 'application/yaml')
|
68
|
+
|
69
|
+
end
|
70
|
+
|
74
71
|
def log_request_url(http, request, start_time)
|
75
72
|
ofset = Time.now - start_time
|
76
73
|
log("HTTP #{request.method} (%0.2fms)" % (ofset * 1000), request_url(http, request))
|
@@ -81,15 +78,22 @@ class HttpLogger
|
|
81
78
|
end
|
82
79
|
|
83
80
|
def log_request_headers(request)
|
84
|
-
if
|
85
|
-
request.each_capitalized
|
81
|
+
if configuration.log_headers
|
82
|
+
request.each_capitalized do |k,v|
|
83
|
+
log_header(:request, k, v)
|
84
|
+
end
|
86
85
|
end
|
87
86
|
end
|
88
87
|
|
88
|
+
def log_header(type, name, value)
|
89
|
+
value = "<filtered>" if name == AUTHORIZATION_HEADER
|
90
|
+
log("HTTP #{type} header", "#{name}: #{value}")
|
91
|
+
end
|
92
|
+
|
89
93
|
HTTP_METHODS_WITH_BODY = Set.new(%w(POST PUT GET PATCH))
|
90
94
|
|
91
95
|
def log_request_body(request)
|
92
|
-
if
|
96
|
+
if configuration.log_request_body
|
93
97
|
if HTTP_METHODS_WITH_BODY.include?(request.method)
|
94
98
|
if (body = request.body) && !body.empty?
|
95
99
|
log("Request body", truncate_body(body))
|
@@ -103,35 +107,39 @@ class HttpLogger
|
|
103
107
|
end
|
104
108
|
|
105
109
|
def log_response_headers(response)
|
106
|
-
if
|
107
|
-
response.each_capitalized
|
110
|
+
if configuration.log_headers
|
111
|
+
response.each_capitalized do |k,v|
|
112
|
+
log_header(:response, k, v)
|
113
|
+
end
|
108
114
|
end
|
109
115
|
end
|
110
116
|
|
111
|
-
def log_response_body(body)
|
112
|
-
if
|
117
|
+
def log_response_body(body, binary)
|
118
|
+
if configuration.log_response_body
|
113
119
|
if body.is_a?(Net::ReadAdapter)
|
114
120
|
log("Response body", "<impossible to log>")
|
115
121
|
else
|
116
122
|
if body && !body.empty?
|
117
|
-
log(
|
123
|
+
log(
|
124
|
+
"Response body",
|
125
|
+
binary ? "<binary #{body.length} bytes>" : truncate_body(body),)
|
118
126
|
end
|
119
127
|
end
|
120
128
|
end
|
121
129
|
end
|
122
130
|
|
123
131
|
def require_logging?(http, request)
|
124
|
-
self.logger && !ignored?(http, request) && (http.started? ||
|
132
|
+
self.logger && !ignored?(http, request) && (http.started? || webmock?(http, request))
|
125
133
|
end
|
126
134
|
|
127
135
|
def ignored?(http, request)
|
128
136
|
url = request_url(http, request)
|
129
|
-
|
137
|
+
configuration.ignore.any? do |pattern|
|
130
138
|
url =~ pattern
|
131
139
|
end
|
132
140
|
end
|
133
141
|
|
134
|
-
def
|
142
|
+
def webmock?(http, request)
|
135
143
|
return false unless defined?(::WebMock)
|
136
144
|
uri = request_uri_as_string(http, request)
|
137
145
|
method = request.method.downcase.to_sym
|
@@ -146,8 +154,8 @@ class HttpLogger
|
|
146
154
|
path = URI.parse(request.path).request_uri if request.path =~ /^http/
|
147
155
|
|
148
156
|
if request["authorization"] =~ /^Basic /
|
149
|
-
userinfo =
|
150
|
-
userinfo =
|
157
|
+
userinfo = WebMock::Utility.decode_userinfo_from_header(request["authorization"])
|
158
|
+
userinfo = WebMock::Utility.encode_unsafe_chars_in_userinfo(userinfo) + "@"
|
151
159
|
else
|
152
160
|
userinfo = ""
|
153
161
|
end
|
@@ -167,11 +175,11 @@ class HttpLogger
|
|
167
175
|
end
|
168
176
|
|
169
177
|
def log(message, dump)
|
170
|
-
self.logger.send(
|
178
|
+
self.logger.send(configuration.level, format_log_entry(message, dump))
|
171
179
|
end
|
172
180
|
|
173
181
|
def format_log_entry(message, dump = nil)
|
174
|
-
if
|
182
|
+
if configuration.colorize
|
175
183
|
message_color, dump_color = "4;32;1", "0;1"
|
176
184
|
log_entry = " \e[#{message_color}m#{message}\e[0m "
|
177
185
|
log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
|
@@ -182,38 +190,43 @@ class HttpLogger
|
|
182
190
|
end
|
183
191
|
|
184
192
|
def logger
|
185
|
-
|
193
|
+
configuration.logger
|
186
194
|
end
|
187
195
|
|
188
196
|
def collapse_body_limit
|
189
|
-
|
197
|
+
configuration.collapse_body_limit
|
198
|
+
end
|
199
|
+
|
200
|
+
def configuration
|
201
|
+
self.class.configuration
|
190
202
|
end
|
191
203
|
end
|
192
204
|
|
193
|
-
|
205
|
+
block = lambda do |a|
|
206
|
+
alias request_without_net_http_logger request
|
194
207
|
def request(request, body = nil, &block)
|
195
208
|
HttpLogger.perform(self, request, body) do
|
196
|
-
|
209
|
+
request_without_net_http_logger(request, body, &block)
|
197
210
|
end
|
211
|
+
|
198
212
|
end
|
199
213
|
end
|
200
214
|
|
201
215
|
if defined?(::WebMock)
|
202
|
-
WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get("@webMockNetHTTP")
|
216
|
+
klass = WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get("@webMockNetHTTP")
|
217
|
+
klass.class_eval(&block)
|
203
218
|
end
|
204
|
-
Net::HTTP.prepend(NetHttpLogger)
|
205
219
|
|
206
|
-
if defined?(Rails)
|
207
220
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
end
|
213
|
-
elsif defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)
|
221
|
+
Net::HTTP.class_eval(&block)
|
222
|
+
|
223
|
+
if defined?(Rails)
|
224
|
+
if defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)
|
214
225
|
# Rails3
|
215
226
|
ActiveSupport.on_load(:after_initialize) do
|
216
|
-
|
227
|
+
unless HttpLogger.configuration.logger
|
228
|
+
HttpLogger.configuration.logger = Rails.logger
|
229
|
+
end
|
217
230
|
end
|
218
231
|
end
|
219
232
|
end
|
data/spec/http_logger_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require "uri"
|
3
|
+
require "base64"
|
3
4
|
|
4
5
|
describe HttpLogger do
|
5
6
|
|
@@ -7,18 +8,21 @@ describe HttpLogger do
|
|
7
8
|
# flush log
|
8
9
|
f = File.open(LOGFILE, "w")
|
9
10
|
f.close
|
11
|
+
|
10
12
|
stub_request(:any, url).to_return(
|
11
13
|
body: response_body,
|
12
|
-
headers: {"X-Http-logger" => true},
|
14
|
+
headers: {"X-Http-logger" => true, **response_headers},
|
13
15
|
)
|
14
16
|
end
|
15
17
|
|
16
18
|
let(:response_body) { "Success" }
|
19
|
+
let(:response_headers) { {} }
|
20
|
+
let(:request_headers) { {} }
|
17
21
|
|
18
22
|
let(:url) { "http://google.com/" }
|
19
23
|
let(:uri) { URI.parse(url) }
|
20
24
|
let(:request) do
|
21
|
-
Net::HTTP.get_response(uri)
|
25
|
+
Net::HTTP.get_response(uri, **request_headers)
|
22
26
|
end
|
23
27
|
|
24
28
|
let(:long_body) do
|
@@ -45,16 +49,20 @@ describe HttpLogger do
|
|
45
49
|
context "when headers logging is on" do
|
46
50
|
|
47
51
|
before(:each) do
|
48
|
-
HttpLogger.log_headers = true
|
52
|
+
HttpLogger.configuration.log_headers = true
|
49
53
|
end
|
50
54
|
|
51
55
|
it { should include("HTTP response header") }
|
52
56
|
it { should include("HTTP request header") }
|
53
57
|
|
54
|
-
after(:each) do
|
55
|
-
HttpLogger.log_headers = false
|
56
|
-
end
|
57
58
|
|
59
|
+
context "authorization header" do
|
60
|
+
|
61
|
+
let(:request_headers) do
|
62
|
+
{'Authorization' => "Basic #{Base64.encode64('hello:world')}".strip}
|
63
|
+
end
|
64
|
+
it { should include("Authorization: <filtered>") }
|
65
|
+
end
|
58
66
|
end
|
59
67
|
|
60
68
|
describe "post request" do
|
@@ -104,7 +112,7 @@ describe HttpLogger do
|
|
104
112
|
context "when request body logging is off" do
|
105
113
|
|
106
114
|
before(:each) do
|
107
|
-
HttpLogger.log_request_body = false
|
115
|
+
HttpLogger.configuration.log_request_body = false
|
108
116
|
end
|
109
117
|
|
110
118
|
let(:request) do
|
@@ -113,9 +121,6 @@ describe HttpLogger do
|
|
113
121
|
|
114
122
|
it { should_not include("Request body") }
|
115
123
|
|
116
|
-
after(:each) do
|
117
|
-
HttpLogger.log_request_body = true
|
118
|
-
end
|
119
124
|
end
|
120
125
|
|
121
126
|
context "with long response body" do
|
@@ -135,7 +140,7 @@ describe HttpLogger do
|
|
135
140
|
context "when response body logging is off" do
|
136
141
|
|
137
142
|
before(:each) do
|
138
|
-
HttpLogger.log_response_body = false
|
143
|
+
HttpLogger.configuration.log_response_body = false
|
139
144
|
end
|
140
145
|
|
141
146
|
let(:response_body) { long_body }
|
@@ -144,10 +149,6 @@ describe HttpLogger do
|
|
144
149
|
end
|
145
150
|
|
146
151
|
it { should_not include("Response body") }
|
147
|
-
|
148
|
-
after(:each) do
|
149
|
-
HttpLogger.log_response_body = true
|
150
|
-
end
|
151
152
|
end
|
152
153
|
|
153
154
|
context "ignore option is set" do
|
@@ -157,14 +158,10 @@ describe HttpLogger do
|
|
157
158
|
end
|
158
159
|
|
159
160
|
before(:each) do
|
160
|
-
HttpLogger.ignore = [/rpm\.newrelic\.com/]
|
161
|
+
HttpLogger.configuration.ignore = [/rpm\.newrelic\.com/]
|
161
162
|
end
|
162
163
|
|
163
164
|
it { should be_empty}
|
164
|
-
|
165
|
-
after(:each) do
|
166
|
-
HttpLogger.ignore = []
|
167
|
-
end
|
168
165
|
end
|
169
166
|
|
170
167
|
context "when level is set" do
|
@@ -175,13 +172,30 @@ describe HttpLogger do
|
|
175
172
|
end
|
176
173
|
|
177
174
|
before(:each) do
|
178
|
-
HttpLogger.level = :info
|
175
|
+
HttpLogger.configuration.level = :info
|
179
176
|
end
|
180
177
|
|
181
178
|
it { should_not be_empty }
|
179
|
+
end
|
182
180
|
|
183
|
-
|
184
|
-
|
181
|
+
context "when binary response" do
|
182
|
+
let(:response_headers) do
|
183
|
+
{
|
184
|
+
'Content-Type' => 'image/webp'
|
185
|
+
}
|
185
186
|
end
|
187
|
+
let(:url) do
|
188
|
+
"http://example.com/image.webp"
|
189
|
+
end
|
190
|
+
|
191
|
+
let(:response_body) do
|
192
|
+
File.read("#{File.dirname(__FILE__)}/image.webp")
|
193
|
+
end
|
194
|
+
|
195
|
+
it { should include("<binary 41887 bytes>") }
|
196
|
+
end
|
197
|
+
|
198
|
+
after(:each) do
|
199
|
+
HttpLogger.configuration.reset
|
186
200
|
end
|
187
201
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: debug
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -67,7 +67,21 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: bump
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -95,7 +109,6 @@ files:
|
|
95
109
|
- LICENSE.txt
|
96
110
|
- Rakefile
|
97
111
|
- Readme.md
|
98
|
-
- VERSION
|
99
112
|
- http_logger.gemspec
|
100
113
|
- lib/http_logger.rb
|
101
114
|
- screenshots/hoptoad.png
|
@@ -107,7 +120,7 @@ homepage: http://github.com/railsware/http_logger
|
|
107
120
|
licenses:
|
108
121
|
- MIT
|
109
122
|
metadata: {}
|
110
|
-
post_install_message:
|
123
|
+
post_install_message:
|
111
124
|
rdoc_options: []
|
112
125
|
require_paths:
|
113
126
|
- lib
|
@@ -122,9 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
135
|
- !ruby/object:Gem::Version
|
123
136
|
version: '0'
|
124
137
|
requirements: []
|
125
|
-
|
126
|
-
|
127
|
-
signing_key:
|
138
|
+
rubygems_version: 3.5.11
|
139
|
+
signing_key:
|
128
140
|
specification_version: 4
|
129
141
|
summary: Log your http api calls just like SQL queries
|
130
142
|
test_files: []
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.6.0
|