http_logger 0.4.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +5 -4
- data/Gemfile.lock +34 -70
- data/Rakefile +3 -14
- data/Readme.md +4 -0
- data/VERSION +1 -1
- data/http_logger.gemspec +32 -32
- data/lib/http_logger.rb +76 -54
- data/spec/http_logger_spec.rb +83 -8
- data/spec/spec_helper.rb +3 -4
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e8cd08ba96dbddfa8f11e4bcbebb2cdde1bc99c19a2603eb2253c1f48d173214
|
4
|
+
data.tar.gz: 0c11b8553de5807f784dd14276017a5b8b7bf6d393e296fb246835bcc6fa0b78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b3bcc69fac4c32215adfa5dac3ba2c0312d67b51a7e6890349bb007a3508f1b91b1b8284c1d835684319e39af6045d2945d8703d43347e130abedffd81bf0fb
|
7
|
+
data.tar.gz: 1a0d722184351705fedb9245f0b74ee2fa315a3df44b956db9561b30bf69b3bce337d179d0f82cb9142239754dd2d2fb363101c1497b85111721079c5b42e1f3
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,79 +1,43 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
addressable (2.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
hashie (2.0.5)
|
31
|
-
highline (1.6.21)
|
32
|
-
jeweler (2.0.1)
|
33
|
-
builder
|
34
|
-
bundler (>= 1.0)
|
35
|
-
git (>= 1.2.5)
|
36
|
-
github_api
|
37
|
-
highline (>= 1.6.15)
|
38
|
-
nokogiri (>= 1.5.10)
|
39
|
-
rake
|
40
|
-
rdoc
|
41
|
-
json (1.8.1)
|
42
|
-
jwt (0.1.11)
|
43
|
-
multi_json (>= 1.5)
|
44
|
-
mini_portile (0.5.3)
|
45
|
-
multi_json (1.9.2)
|
46
|
-
multi_xml (0.5.5)
|
47
|
-
multipart-post (2.0.0)
|
48
|
-
nokogiri (1.6.1)
|
49
|
-
mini_portile (~> 0.5.0)
|
50
|
-
oauth2 (0.9.3)
|
51
|
-
faraday (>= 0.8, < 0.10)
|
52
|
-
jwt (~> 0.1.8)
|
53
|
-
multi_json (~> 1.3)
|
54
|
-
multi_xml (~> 0.5)
|
55
|
-
rack (~> 1.2)
|
56
|
-
rack (1.5.2)
|
57
|
-
rake (10.2.2)
|
58
|
-
rdoc (4.1.1)
|
59
|
-
json (~> 1.4)
|
60
|
-
rspec (2.9.0)
|
61
|
-
rspec-core (~> 2.9.0)
|
62
|
-
rspec-expectations (~> 2.9.0)
|
63
|
-
rspec-mocks (~> 2.9.0)
|
64
|
-
rspec-core (2.9.0)
|
65
|
-
rspec-expectations (2.9.1)
|
66
|
-
diff-lcs (~> 1.1.3)
|
67
|
-
rspec-mocks (2.9.0)
|
68
|
-
thread_safe (0.3.1)
|
69
|
-
atomic (>= 1.1.7, < 2)
|
4
|
+
addressable (2.4.0)
|
5
|
+
bump (0.10.0)
|
6
|
+
byebug (11.1.3)
|
7
|
+
crack (0.4.5)
|
8
|
+
rexml
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
hashdiff (1.0.1)
|
11
|
+
rake (13.0.6)
|
12
|
+
rexml (3.2.5)
|
13
|
+
rspec (3.10.0)
|
14
|
+
rspec-core (~> 3.10.0)
|
15
|
+
rspec-expectations (~> 3.10.0)
|
16
|
+
rspec-mocks (~> 3.10.0)
|
17
|
+
rspec-core (3.10.1)
|
18
|
+
rspec-support (~> 3.10.0)
|
19
|
+
rspec-expectations (3.10.1)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.10.0)
|
22
|
+
rspec-mocks (3.10.2)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.10.0)
|
25
|
+
rspec-support (3.10.3)
|
26
|
+
webmock (3.13.0)
|
27
|
+
addressable (>= 2.3.6)
|
28
|
+
crack (>= 0.3.2)
|
29
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
70
30
|
|
71
31
|
PLATFORMS
|
72
|
-
|
32
|
+
x86_64-darwin-19
|
73
33
|
|
74
34
|
DEPENDENCIES
|
35
|
+
bump (~> 0.10.0)
|
75
36
|
bundler
|
76
|
-
|
77
|
-
|
78
|
-
jeweler
|
37
|
+
byebug
|
38
|
+
rake
|
79
39
|
rspec
|
40
|
+
webmock
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
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
@@ -24,6 +24,10 @@ HttpLogger.logger = Logger.new(...) # defaults to Rails.logger if Rails is defin
|
|
24
24
|
HttpLogger.colorize = true # Default: true
|
25
25
|
HttpLogger.ignore = [/newrelic\.com/]
|
26
26
|
HttpLogger.log_headers = false # Default: false
|
27
|
+
HttpLogger.log_request_body = false # Default: true
|
28
|
+
HttpLogger.log_response_body = false # Default: true
|
29
|
+
HttpLogger.level = :info # Desired log level as a symbol. Default: :debug
|
30
|
+
HttpLogger.collapse_body_limit # Change default truncate limit. Default: 5000
|
27
31
|
```
|
28
32
|
|
29
33
|
## Alternative
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/http_logger.gemspec
CHANGED
@@ -1,19 +1,19 @@
|
|
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
|
-
s.name = "http_logger"
|
9
|
-
s.version =
|
8
|
+
s.name = "http_logger".freeze
|
9
|
+
s.version = HttpLogger::VERSION
|
10
10
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.require_paths = ["lib"]
|
13
|
-
s.authors = ["Bogdan Gusiev"]
|
14
|
-
s.date = "
|
15
|
-
s.description = "This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file"
|
16
|
-
s.email = "agresso@gmail.com"
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Bogdan Gusiev".freeze]
|
14
|
+
s.date = "2020-01-27"
|
15
|
+
s.description = "This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file".freeze
|
16
|
+
s.email = "agresso@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE.txt"
|
19
19
|
]
|
@@ -34,33 +34,33 @@ Gem::Specification.new do |s|
|
|
34
34
|
"spec/http_logger_spec.rb",
|
35
35
|
"spec/spec_helper.rb"
|
36
36
|
]
|
37
|
-
s.homepage = "http://github.com/railsware/http_logger"
|
38
|
-
s.licenses = ["MIT"]
|
39
|
-
s.rubygems_version = "2.
|
40
|
-
s.summary = "Log your http api calls just like SQL queries"
|
37
|
+
s.homepage = "http://github.com/railsware/http_logger".freeze
|
38
|
+
s.licenses = ["MIT".freeze]
|
39
|
+
s.rubygems_version = "2.7.8".freeze
|
40
|
+
s.summary = "Log your http api calls just like SQL queries".freeze
|
41
41
|
|
42
42
|
if s.respond_to? :specification_version then
|
43
43
|
s.specification_version = 4
|
44
44
|
|
45
45
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
-
s.add_development_dependency(%q<
|
47
|
-
s.add_development_dependency(%q<
|
48
|
-
s.add_development_dependency(%q<
|
49
|
-
s.add_development_dependency(%q<
|
50
|
-
s.add_development_dependency(%q<
|
46
|
+
s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
|
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
51
|
else
|
52
|
-
s.add_dependency(%q<
|
53
|
-
s.add_dependency(%q<
|
54
|
-
s.add_dependency(%q<
|
55
|
-
s.add_dependency(%q<
|
56
|
-
s.add_dependency(%q<
|
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
57
|
end
|
58
58
|
else
|
59
|
-
s.add_dependency(%q<
|
60
|
-
s.add_dependency(%q<
|
61
|
-
s.add_dependency(%q<
|
62
|
-
s.add_dependency(%q<
|
63
|
-
s.add_dependency(%q<
|
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
64
|
end
|
65
65
|
end
|
66
66
|
|
data/lib/http_logger.rb
CHANGED
@@ -22,18 +22,26 @@ require 'set'
|
|
22
22
|
#
|
23
23
|
# cat /tmp/all.log
|
24
24
|
class HttpLogger
|
25
|
+
AUTHORIZATION_HEADER = 'Authorization'
|
26
|
+
|
25
27
|
class << self
|
26
28
|
attr_accessor :collapse_body_limit
|
27
29
|
attr_accessor :log_headers
|
30
|
+
attr_accessor :log_request_body
|
31
|
+
attr_accessor :log_response_body
|
28
32
|
attr_accessor :logger
|
29
33
|
attr_accessor :colorize
|
30
34
|
attr_accessor :ignore
|
35
|
+
attr_accessor :level
|
31
36
|
end
|
32
37
|
|
33
38
|
self.log_headers = false
|
39
|
+
self.log_request_body = true
|
40
|
+
self.log_response_body = true
|
34
41
|
self.colorize = true
|
35
42
|
self.collapse_body_limit = 5000
|
36
43
|
self.ignore = []
|
44
|
+
self.level = :debug
|
37
45
|
|
38
46
|
def self.perform(*args, &block)
|
39
47
|
instance.perform(*args, &block)
|
@@ -71,21 +79,30 @@ class HttpLogger
|
|
71
79
|
end
|
72
80
|
|
73
81
|
def request_url(http, request)
|
74
|
-
URI.
|
82
|
+
URI::DEFAULT_PARSER.unescape("http#{"s" if http.use_ssl?}://#{http.address}:#{http.port}#{request.path}")
|
75
83
|
end
|
76
84
|
|
77
85
|
def log_request_headers(request)
|
78
86
|
if self.class.log_headers
|
79
|
-
request.each_capitalized
|
87
|
+
request.each_capitalized do |k,v|
|
88
|
+
log_header(:request, k, v)
|
89
|
+
end
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
83
|
-
|
84
|
-
|
93
|
+
def log_header(type, name, value)
|
94
|
+
value = "<filtered>" if name == AUTHORIZATION_HEADER
|
95
|
+
log("HTTP #{type} header", "#{name}: #{value}")
|
96
|
+
end
|
97
|
+
|
98
|
+
HTTP_METHODS_WITH_BODY = Set.new(%w(POST PUT GET PATCH))
|
99
|
+
|
85
100
|
def log_request_body(request)
|
86
|
-
if
|
87
|
-
if (
|
88
|
-
|
101
|
+
if self.class.log_request_body
|
102
|
+
if HTTP_METHODS_WITH_BODY.include?(request.method)
|
103
|
+
if (body = request.body) && !body.empty?
|
104
|
+
log("Request body", truncate_body(body))
|
105
|
+
end
|
89
106
|
end
|
90
107
|
end
|
91
108
|
end
|
@@ -95,53 +112,74 @@ class HttpLogger
|
|
95
112
|
end
|
96
113
|
|
97
114
|
def log_response_headers(response)
|
98
|
-
if
|
99
|
-
response.each_capitalized
|
115
|
+
if HttpLogger.log_headers
|
116
|
+
response.each_capitalized do |k,v|
|
117
|
+
log_header(:response, k, v)
|
118
|
+
end
|
100
119
|
end
|
101
120
|
end
|
102
121
|
|
103
122
|
def log_response_body(body)
|
104
|
-
if
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
123
|
+
if HttpLogger.log_response_body
|
124
|
+
if body.is_a?(Net::ReadAdapter)
|
125
|
+
log("Response body", "<impossible to log>")
|
126
|
+
else
|
127
|
+
if body && !body.empty?
|
128
|
+
log("Response body", truncate_body(body))
|
129
|
+
end
|
109
130
|
end
|
110
131
|
end
|
111
132
|
end
|
112
133
|
|
113
134
|
def require_logging?(http, request)
|
114
|
-
|
135
|
+
|
136
|
+
self.logger && !ignored?(http, request) && (http.started? || webmock?(http, request))
|
115
137
|
end
|
116
138
|
|
117
139
|
def ignored?(http, request)
|
118
140
|
url = request_url(http, request)
|
119
|
-
|
141
|
+
HttpLogger.ignore.any? do |pattern|
|
120
142
|
url =~ pattern
|
121
143
|
end
|
122
144
|
end
|
123
145
|
|
124
|
-
def
|
125
|
-
return false unless defined?(::
|
126
|
-
uri =
|
146
|
+
def webmock?(http, request)
|
147
|
+
return false unless defined?(::WebMock)
|
148
|
+
uri = request_uri_as_string(http, request)
|
127
149
|
method = request.method.downcase.to_sym
|
128
|
-
::
|
150
|
+
signature = WebMock::RequestSignature.new(method, uri)
|
151
|
+
::WebMock.registered_request?(signature)
|
152
|
+
end
|
153
|
+
|
154
|
+
def request_uri_as_string(net_http, request)
|
155
|
+
protocol = net_http.use_ssl? ? "https" : "http"
|
156
|
+
|
157
|
+
path = request.path
|
158
|
+
path = URI.parse(request.path).request_uri if request.path =~ /^http/
|
159
|
+
|
160
|
+
if request["authorization"] =~ /^Basic /
|
161
|
+
userinfo = WebMock::Utility.decode_userinfo_from_header(request["authorization"])
|
162
|
+
userinfo = WebMock::Utility.encode_unsafe_chars_in_userinfo(userinfo) + "@"
|
163
|
+
else
|
164
|
+
userinfo = ""
|
165
|
+
end
|
166
|
+
|
167
|
+
"#{protocol}://#{userinfo}#{net_http.address}:#{net_http.port}#{path}"
|
129
168
|
end
|
130
169
|
|
131
170
|
def truncate_body(body)
|
132
171
|
if collapse_body_limit && collapse_body_limit > 0 && body && body.size >= collapse_body_limit
|
133
172
|
body_piece_size = collapse_body_limit / 2
|
134
|
-
body[0..body_piece_size] +
|
135
|
-
"\n\n<some data truncated>\n\n" +
|
173
|
+
body[0..body_piece_size] +
|
174
|
+
"\n\n<some data truncated>\n\n" +
|
136
175
|
body[(body.size - body_piece_size)..body.size]
|
137
176
|
else
|
138
177
|
body
|
139
178
|
end
|
140
179
|
end
|
141
180
|
|
142
|
-
|
143
181
|
def log(message, dump)
|
144
|
-
self.logger.
|
182
|
+
self.logger.send(self.class.level, format_log_entry(message, dump))
|
145
183
|
end
|
146
184
|
|
147
185
|
def format_log_entry(message, dump = nil)
|
@@ -164,47 +202,31 @@ class HttpLogger
|
|
164
202
|
end
|
165
203
|
end
|
166
204
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
HttpLogger.deprecate_config("log_headers")
|
171
|
-
HttpLogger.log_headers = value
|
172
|
-
end
|
173
|
-
|
174
|
-
def self.colorize=(value)
|
175
|
-
HttpLogger.deprecate_config("colorize")
|
176
|
-
HttpLogger.colorize = value
|
177
|
-
end
|
178
|
-
|
179
|
-
def self.logger=(value)
|
180
|
-
HttpLogger.deprecate_config("logger")
|
181
|
-
HttpLogger.logger = value
|
182
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
alias_method :request_without_logging, :request
|
186
|
-
|
205
|
+
block = lambda do |a|
|
206
|
+
# raise instance_methods.inspect
|
207
|
+
alias request_without_net_http_logger request
|
187
208
|
def request(request, body = nil, &block)
|
188
209
|
HttpLogger.perform(self, request, body) do
|
189
|
-
|
210
|
+
request_without_net_http_logger(request, body, &block)
|
190
211
|
end
|
212
|
+
|
191
213
|
end
|
214
|
+
end
|
192
215
|
|
216
|
+
if defined?(::WebMock)
|
217
|
+
klass = WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get("@webMockNetHTTP")
|
218
|
+
# raise klass.instance_methods.inspect
|
219
|
+
klass.class_eval(&block)
|
193
220
|
end
|
194
221
|
|
195
|
-
if defined?(Rails)
|
196
222
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
end
|
202
|
-
elsif defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)
|
223
|
+
Net::HTTP.class_eval(&block)
|
224
|
+
|
225
|
+
if defined?(Rails)
|
226
|
+
if defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)
|
203
227
|
# Rails3
|
204
228
|
ActiveSupport.on_load(:after_initialize) do
|
205
229
|
HttpLogger.logger = Rails.logger unless HttpLogger.logger
|
206
230
|
end
|
207
231
|
end
|
208
232
|
end
|
209
|
-
|
210
|
-
|
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,12 +8,20 @@ describe HttpLogger do
|
|
7
8
|
# flush log
|
8
9
|
f = File.open(LOGFILE, "w")
|
9
10
|
f.close
|
11
|
+
stub_request(:any, url).to_return(
|
12
|
+
body: response_body,
|
13
|
+
headers: {"X-Http-logger" => true, **response_headers},
|
14
|
+
)
|
10
15
|
end
|
11
16
|
|
17
|
+
let(:response_body) { "Success" }
|
18
|
+
let(:response_headers) { {} }
|
19
|
+
let(:request_headers) { {} }
|
20
|
+
|
12
21
|
let(:url) { "http://google.com/" }
|
13
22
|
let(:uri) { URI.parse(url) }
|
14
23
|
let(:request) do
|
15
|
-
Net::HTTP.get_response(uri)
|
24
|
+
Net::HTTP.get_response(uri, **request_headers)
|
16
25
|
end
|
17
26
|
|
18
27
|
let(:long_body) do
|
@@ -33,7 +42,7 @@ describe HttpLogger do
|
|
33
42
|
let(:url) { "http://google.com?query=a%20b"}
|
34
43
|
|
35
44
|
it { subject.should include("query=a b")}
|
36
|
-
|
45
|
+
|
37
46
|
end
|
38
47
|
|
39
48
|
context "when headers logging is on" do
|
@@ -45,10 +54,19 @@ describe HttpLogger do
|
|
45
54
|
it { should include("HTTP response header") }
|
46
55
|
it { should include("HTTP request header") }
|
47
56
|
|
57
|
+
|
58
|
+
context "authorization header" do
|
59
|
+
|
60
|
+
let(:request_headers) do
|
61
|
+
{'Authorization' => "Basic #{Base64.encode64('hello:world')}".strip}
|
62
|
+
end
|
63
|
+
it { should include("Authorization: <filtered>") }
|
64
|
+
end
|
65
|
+
|
48
66
|
after(:each) do
|
49
67
|
HttpLogger.log_headers = false
|
50
68
|
end
|
51
|
-
|
69
|
+
|
52
70
|
end
|
53
71
|
|
54
72
|
describe "post request" do
|
@@ -60,8 +78,8 @@ describe HttpLogger do
|
|
60
78
|
it {should include("Request body")}
|
61
79
|
it {should include("a=hello&b=1")}
|
62
80
|
context "with too long body" do
|
81
|
+
let(:response_body) { long_body }
|
63
82
|
let(:url) do
|
64
|
-
FakeWeb.register_uri(:post, "http://github.com", :body => long_body)
|
65
83
|
"http://github.com/"
|
66
84
|
end
|
67
85
|
it { should include("12,Dodo case,dodo@case.com,tech@dodcase.com,single elimination\n")}
|
@@ -70,6 +88,7 @@ describe HttpLogger do
|
|
70
88
|
end
|
71
89
|
|
72
90
|
end
|
91
|
+
|
73
92
|
describe "put request" do
|
74
93
|
let(:request) do
|
75
94
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -81,7 +100,7 @@ describe HttpLogger do
|
|
81
100
|
it {should include("Request body")}
|
82
101
|
it {should include("a=hello&b=1")}
|
83
102
|
end
|
84
|
-
|
103
|
+
|
85
104
|
describe "generic request" do
|
86
105
|
let(:request) do
|
87
106
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -94,10 +113,28 @@ describe HttpLogger do
|
|
94
113
|
it {should include("a=hello&b=1")}
|
95
114
|
end
|
96
115
|
|
116
|
+
context "when request body logging is off" do
|
117
|
+
|
118
|
+
before(:each) do
|
119
|
+
HttpLogger.log_request_body = false
|
120
|
+
end
|
121
|
+
|
122
|
+
let(:request) do
|
123
|
+
Net::HTTP.post_form(uri, {})
|
124
|
+
end
|
125
|
+
|
126
|
+
it { should_not include("Request body") }
|
127
|
+
|
128
|
+
after(:each) do
|
129
|
+
HttpLogger.log_request_body = true
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
97
133
|
context "with long response body" do
|
98
134
|
|
135
|
+
let(:response_body) { long_body }
|
99
136
|
let(:url) do
|
100
|
-
|
137
|
+
stub_request(:get, "http://github.com/").to_return(body: long_body)
|
101
138
|
"http://github.com"
|
102
139
|
end
|
103
140
|
|
@@ -107,18 +144,56 @@ describe HttpLogger do
|
|
107
144
|
|
108
145
|
end
|
109
146
|
|
147
|
+
context "when response body logging is off" do
|
148
|
+
|
149
|
+
before(:each) do
|
150
|
+
HttpLogger.log_response_body = false
|
151
|
+
end
|
152
|
+
|
153
|
+
let(:response_body) { long_body }
|
154
|
+
let(:url) do
|
155
|
+
"http://github.com"
|
156
|
+
end
|
157
|
+
|
158
|
+
it { should_not include("Response body") }
|
159
|
+
|
160
|
+
after(:each) do
|
161
|
+
HttpLogger.log_response_body = true
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
110
165
|
context "ignore option is set" do
|
111
166
|
|
112
|
-
let(:url)
|
167
|
+
let(:url) do
|
168
|
+
"http://rpm.newrelic.com/hello/world"
|
169
|
+
end
|
113
170
|
|
114
171
|
before(:each) do
|
115
172
|
HttpLogger.ignore = [/rpm\.newrelic\.com/]
|
116
173
|
end
|
117
174
|
|
118
175
|
it { should be_empty}
|
119
|
-
|
176
|
+
|
120
177
|
after(:each) do
|
121
178
|
HttpLogger.ignore = []
|
122
179
|
end
|
123
180
|
end
|
181
|
+
|
182
|
+
context "when level is set" do
|
183
|
+
|
184
|
+
let(:url) do
|
185
|
+
stub_request(:get, "http://rpm.newrelic.com/hello/world").to_return(body: "")
|
186
|
+
"http://rpm.newrelic.com/hello/world"
|
187
|
+
end
|
188
|
+
|
189
|
+
before(:each) do
|
190
|
+
HttpLogger.level = :info
|
191
|
+
end
|
192
|
+
|
193
|
+
it { should_not be_empty }
|
194
|
+
|
195
|
+
after(:each) do
|
196
|
+
HttpLogger.level = :debug
|
197
|
+
end
|
198
|
+
end
|
124
199
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
|
-
require '
|
4
|
+
require 'webmock/rspec'
|
5
5
|
require 'http_logger'
|
6
6
|
require "logger"
|
7
7
|
require "fileutils"
|
@@ -11,10 +11,9 @@ require "fileutils"
|
|
11
11
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
12
|
|
13
13
|
LOGFILE = 'http.log'
|
14
|
-
RSpec.configure do |config|
|
15
|
-
|
16
14
|
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.expect_with(:rspec) { |c| c.syntax = :should }
|
17
17
|
FileUtils.rm_f(LOGFILE)
|
18
18
|
HttpLogger.logger = Logger.new(LOGFILE)
|
19
|
-
|
20
19
|
end
|
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: 0.7.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
|
-
date:
|
11
|
+
date: 2020-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: byebug
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: webmock
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: jeweler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -107,7 +107,7 @@ homepage: http://github.com/railsware/http_logger
|
|
107
107
|
licenses:
|
108
108
|
- MIT
|
109
109
|
metadata: {}
|
110
|
-
post_install_message:
|
110
|
+
post_install_message:
|
111
111
|
rdoc_options: []
|
112
112
|
require_paths:
|
113
113
|
- lib
|
@@ -122,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
|
-
|
126
|
-
|
127
|
-
signing_key:
|
125
|
+
rubygems_version: 3.2.22
|
126
|
+
signing_key:
|
128
127
|
specification_version: 4
|
129
128
|
summary: Log your http api calls just like SQL queries
|
130
129
|
test_files: []
|