httplog 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/.rubocop.yml +55 -0
- data/.rubocop_todo.yml +36 -0
- data/.travis.yml +0 -1
- data/Gemfile +3 -1
- data/Gemfile.lock +2 -2
- data/Guardfile +10 -9
- data/README.md +7 -1
- data/Rakefile +7 -5
- data/gemfiles/http2.gemfile +5 -3
- data/gemfiles/http3.gemfile +5 -3
- data/gemfiles/http4.gemfile +5 -3
- data/gemfiles/rack1.gemfile +5 -3
- data/gemfiles/rack2.gemfile +5 -3
- data/httplog.gemspec +29 -28
- data/lib/httplog.rb +11 -9
- data/lib/httplog/adapters/ethon.rb +7 -9
- data/lib/httplog/adapters/excon.rb +9 -11
- data/lib/httplog/adapters/http.rb +9 -10
- data/lib/httplog/adapters/httpclient.rb +7 -4
- data/lib/httplog/adapters/net_http.rb +5 -5
- data/lib/httplog/adapters/patron.rb +4 -2
- data/lib/httplog/configuration.rb +4 -5
- data/lib/httplog/http_log.rb +33 -26
- data/lib/httplog/version.rb +3 -1
- data/spec/adapters/ethon_adapter.rb +6 -4
- data/spec/adapters/excon_adapter.rb +3 -1
- data/spec/adapters/faraday_adapter.rb +3 -1
- data/spec/adapters/http_adapter.rb +2 -0
- data/spec/adapters/http_base_adapter.rb +10 -8
- data/spec/adapters/httparty_adapter.rb +2 -0
- data/spec/adapters/httpclient_adapter.rb +2 -0
- data/spec/adapters/net_http_adapter.rb +5 -5
- data/spec/adapters/open_uri_adapter.rb +4 -2
- data/spec/adapters/patron_adapter.rb +4 -2
- data/spec/adapters/typhoeus_adapter.rb +2 -1
- data/spec/configuration_spec.rb +5 -6
- data/spec/lib/http_client_spec.rb +15 -0
- data/spec/lib/http_log_spec.rb +333 -0
- data/spec/spec_helper.rb +7 -7
- data/spec/support/not_gzipped.html.gz +8 -0
- data/spec/support/test_server.rb +16 -14
- metadata +43 -39
- data/spec/http_log_spec.rb +0 -358
data/spec/support/test_server.rb
CHANGED
@@ -1,31 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'rack'
|
3
5
|
|
4
6
|
module Httplog
|
5
7
|
module Test
|
6
|
-
|
7
|
-
|
8
|
-
@root =
|
8
|
+
class Server
|
9
|
+
def call(env)
|
10
|
+
@root = __dir__
|
9
11
|
path = Rack::Utils.unescape(env['PATH_INFO'])
|
10
12
|
path += 'index.html' if path == '/'
|
11
|
-
file = @root +
|
13
|
+
file = @root + path.to_s
|
12
14
|
|
13
15
|
params = Rack::Utils.parse_nested_query(env['QUERY_STRING'])
|
14
16
|
|
15
|
-
headers = {
|
17
|
+
headers = { 'Content-Type' => 'text/html' }
|
16
18
|
|
17
19
|
if params['redirect']
|
18
|
-
[
|
20
|
+
[301, { 'Location' => '/index.html' }, '']
|
19
21
|
|
20
|
-
elsif File.
|
21
|
-
headers[
|
22
|
-
headers[
|
23
|
-
headers[
|
24
|
-
[
|
22
|
+
elsif File.exist?(file)
|
23
|
+
headers['Content-Type'] = 'application/octet-stream' if File.extname(file) == '.bin'
|
24
|
+
headers['Content-Type'] = 'text/html; charset=UTF-8' if path =~ /utf8/
|
25
|
+
headers['Content-Encoding'] = 'gzip' if File.extname(file) == '.gz'
|
26
|
+
[200, headers, File.binread(file)]
|
25
27
|
else
|
26
|
-
[
|
28
|
+
[404, { 'Content-Type' => 'text/plain' }, 'file not found']
|
27
29
|
end
|
28
|
-
|
29
|
-
|
30
|
+
end
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
metadata
CHANGED
@@ -1,127 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httplog
|
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
|
- Thilo Rusche
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: ethon
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0.11'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0.11'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: excon
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0.60'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.60'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: faraday
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0.14'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0.14'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: guard-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '4.7'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '4.7'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: http
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
75
|
+
version: '3.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
82
|
+
version: '3.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: httparty
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.16'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.16'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: httpclient
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '2.8'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '2.8'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: listen
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0
|
117
|
+
version: '3.0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0
|
124
|
+
version: '3.0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: patron
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,61 +137,61 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0.12'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: rake
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '3
|
145
|
+
version: '12.3'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '3
|
152
|
+
version: '12.3'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: rspec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
159
|
+
version: '3.7'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
166
|
+
version: '3.7'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: simplecov
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: '
|
173
|
+
version: '0.15'
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: '
|
180
|
+
version: '0.15'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
182
|
+
name: thin
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: '
|
187
|
+
version: '1.7'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: '
|
194
|
+
version: '1.7'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: colorize
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -230,6 +230,8 @@ extra_rdoc_files: []
|
|
230
230
|
files:
|
231
231
|
- ".gitignore"
|
232
232
|
- ".rspec"
|
233
|
+
- ".rubocop.yml"
|
234
|
+
- ".rubocop_todo.yml"
|
233
235
|
- ".ruby-version"
|
234
236
|
- ".travis.yml"
|
235
237
|
- CHANGELOG.md
|
@@ -267,12 +269,14 @@ files:
|
|
267
269
|
- spec/adapters/patron_adapter.rb
|
268
270
|
- spec/adapters/typhoeus_adapter.rb
|
269
271
|
- spec/configuration_spec.rb
|
270
|
-
- spec/
|
272
|
+
- spec/lib/http_client_spec.rb
|
273
|
+
- spec/lib/http_log_spec.rb
|
271
274
|
- spec/log/.gitkeep
|
272
275
|
- spec/spec_helper.rb
|
273
276
|
- spec/support/index.html
|
274
277
|
- spec/support/index.html.gz
|
275
278
|
- spec/support/log4r.yml
|
279
|
+
- spec/support/not_gzipped.html.gz
|
276
280
|
- spec/support/test.bin
|
277
281
|
- spec/support/test_server.rb
|
278
282
|
- spec/support/utf8-invalid.html
|
data/spec/http_log_spec.rb
DELETED
@@ -1,358 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe HttpLog do
|
6
|
-
|
7
|
-
let(:host) { 'localhost' }
|
8
|
-
let(:port) { 9292 }
|
9
|
-
let(:path) { "/index.html" }
|
10
|
-
let(:headers) { { "accept" => "*/*", "foo" => "bar" } }
|
11
|
-
let(:data) { "foo=bar&bar=foo" }
|
12
|
-
let(:params) { {'foo' => 'bar:form-data', 'bar' => 'foo'} }
|
13
|
-
|
14
|
-
ADAPTERS = [
|
15
|
-
NetHTTPAdapter,
|
16
|
-
OpenUriAdapter,
|
17
|
-
HTTPClientAdapter,
|
18
|
-
HTTPartyAdapter,
|
19
|
-
FaradayAdapter,
|
20
|
-
ExconAdapter,
|
21
|
-
EthonAdapter,
|
22
|
-
# FIXME: typheous does weird things to reponse headers using ethon as the default adapter,
|
23
|
-
# even though ethon stand-alone works just fine. Not worth supporting since Typhoeus has its
|
24
|
-
# own logging facility.
|
25
|
-
#
|
26
|
-
# TyphoeusAdapter,
|
27
|
-
PatronAdapter,
|
28
|
-
HTTPAdapter
|
29
|
-
]
|
30
|
-
|
31
|
-
ADAPTERS.each do |adapter_class|
|
32
|
-
context adapter_class, :adapter => adapter_class.to_s do
|
33
|
-
let(:adapter) { adapter_class.new(host, port, path, headers, data, params) }
|
34
|
-
|
35
|
-
context "with default configuration" do
|
36
|
-
connection_test_method = adapter_class.is_libcurl? ? :to_not : :to
|
37
|
-
|
38
|
-
if adapter_class.method_defined? :send_get_request
|
39
|
-
it "should log GET requests" do
|
40
|
-
res = adapter.send_get_request
|
41
|
-
|
42
|
-
expect(log).send(connection_test_method, include(HttpLog::LOG_PREFIX + "Connecting: #{host}:#{port}"))
|
43
|
-
|
44
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Sending: GET http://#{host}:#{port}#{path}")
|
45
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Data:")
|
46
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Header:")
|
47
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Status: 200")
|
48
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Benchmark: ")
|
49
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Response:#{adapter.expected_response_body}")
|
50
|
-
expect(log.colorized?).to be_falsey
|
51
|
-
|
52
|
-
expect(res).to be_a adapter.response if adapter.respond_to? :response
|
53
|
-
end
|
54
|
-
|
55
|
-
context "with gzipped response body" do
|
56
|
-
let(:path) { '/index.html.gz' }
|
57
|
-
let(:data) { nil }
|
58
|
-
|
59
|
-
it "decompresses gzipped response body" do
|
60
|
-
adapter.send_get_request
|
61
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Response:#{adapter.expected_response_body}")
|
62
|
-
end
|
63
|
-
|
64
|
-
if adapter_class.method_defined? :send_head_request
|
65
|
-
it "doesn't try to decompress body for HEAD requests" do
|
66
|
-
adapter.send_head_request
|
67
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Response:")
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "with UTF-8 response body" do
|
73
|
-
let(:path) { '/utf8.html' }
|
74
|
-
let(:data) { nil }
|
75
|
-
|
76
|
-
it "works" do
|
77
|
-
adapter.send_get_request
|
78
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Response:#{adapter.expected_response_body}")
|
79
|
-
if adapter.logs_data?
|
80
|
-
expect(log).to include(" <title>Блог Яндекса</title>")
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "with binary response body" do
|
86
|
-
let(:path) { '/test.bin' }
|
87
|
-
let(:data) { nil }
|
88
|
-
|
89
|
-
it "doesn't log response" do
|
90
|
-
adapter.send_get_request
|
91
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Response: (not showing binary data)")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
if adapter_class.method_defined? :send_post_request
|
97
|
-
it "logs POST requests" do
|
98
|
-
res = adapter.send_post_request
|
99
|
-
|
100
|
-
expect(log).send(connection_test_method, include(HttpLog::LOG_PREFIX + "Connecting: #{host}:#{port}"))
|
101
|
-
|
102
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Sending: POST http://#{host}:#{port}#{path}")
|
103
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Data: foo=bar&bar=foo")
|
104
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Header:")
|
105
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Status: 200")
|
106
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Benchmark: ")
|
107
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Response:#{adapter.expected_response_body}")
|
108
|
-
expect(log.colorized?).to be_falsey
|
109
|
-
|
110
|
-
expect(res).to be_a adapter.response if adapter.respond_to? :response
|
111
|
-
end
|
112
|
-
|
113
|
-
context "with non-UTF request data" do
|
114
|
-
let(:data) { "a UTF-8 striñg with an 8BIT-ASCII character: \xC3".freeze }
|
115
|
-
it "does not raise and error" do
|
116
|
-
expect {adapter.send_post_request }.to_not raise_error
|
117
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Response:")
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "with URI encoded non-UTF data" do
|
122
|
-
let(:data) { "a UTF-8 striñg with a URI encoded 8BIT-ASCII character: %c3" }
|
123
|
-
it "does not raise and error" do
|
124
|
-
expect { adapter.send_post_request }.to_not raise_error
|
125
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Response:")
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context "with custom configuration" do
|
132
|
-
context "GET requests" do
|
133
|
-
|
134
|
-
it "should not log anything unless enabled is set" do
|
135
|
-
HttpLog.configure { |c| c.enabled = false }
|
136
|
-
adapter.send_get_request
|
137
|
-
expect(log).to eq('')
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should log at other levels" do
|
141
|
-
HttpLog.configure { |c| c.severity = Logger::Severity::INFO }
|
142
|
-
adapter.send_get_request
|
143
|
-
expect(log).to include("INFO")
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should log headers if enabled" do
|
147
|
-
HttpLog.configure { |c| c.log_headers = true }
|
148
|
-
adapter.send_get_request
|
149
|
-
# request header
|
150
|
-
expect(log.downcase).to include(HttpLog::LOG_PREFIX + "Header: accept: */*".downcase)
|
151
|
-
# response header
|
152
|
-
expect(log.downcase).to include(HttpLog::LOG_PREFIX + "Header: server: thin".downcase)
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should not log headers if disabled" do
|
156
|
-
HttpLog.configure { |c| c.log_headers = false }
|
157
|
-
adapter.send_get_request
|
158
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Header:")
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should log the request if url does not match blacklist pattern" do
|
162
|
-
HttpLog.configure { |c| c.url_blacklist_pattern = /example.com/ }
|
163
|
-
adapter.send_get_request
|
164
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Sending: GET")
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should log the request if url matches whitelist pattern and not the blacklist pattern" do
|
168
|
-
HttpLog.configure { |c| c.url_blacklist_pattern = /example.com/ }
|
169
|
-
HttpLog.configure { |c| c.url_whitelist_pattern = /#{host}:#{port}/ }
|
170
|
-
adapter.send_get_request
|
171
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Sending: GET")
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should not log the request if url matches blacklist pattern" do
|
175
|
-
HttpLog.configure { |c| c.url_blacklist_pattern = /#{host}:#{port}/ }
|
176
|
-
adapter.send_get_request
|
177
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Sending: GET")
|
178
|
-
end
|
179
|
-
|
180
|
-
it "should not log the request if url does not match whitelist pattern" do
|
181
|
-
HttpLog.configure { |c| c.url_whitelist_pattern = /example.com/ }
|
182
|
-
adapter.send_get_request
|
183
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Sending: GET")
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should not log the request if url matches blacklist pattern and the whitelist pattern" do
|
187
|
-
HttpLog.configure { |c| c.url_blacklist_pattern = /#{host}:#{port}/ }
|
188
|
-
HttpLog.configure { |c| c.url_whitelist_pattern = /#{host}:#{port}/ }
|
189
|
-
adapter.send_get_request
|
190
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Sending: GET")
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should not log the request if disabled" do
|
194
|
-
HttpLog.configure { |c| c.log_request = false }
|
195
|
-
adapter.send_get_request
|
196
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Sending: GET")
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should not log the connection if disabled" do
|
200
|
-
HttpLog.configure { |c| c.log_connect = false }
|
201
|
-
adapter.send_get_request
|
202
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Connecting: #{host}:#{port}")
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should not log data if disabled" do
|
206
|
-
HttpLog.configure { |c| c.log_data = false }
|
207
|
-
adapter.send_get_request
|
208
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Data:")
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should colorized output" do
|
212
|
-
HttpLog.configure { |c| c.color = :red }
|
213
|
-
adapter.send_get_request
|
214
|
-
expect(log.colorized?).to be_truthy
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should log with custom string prefix" do
|
218
|
-
HttpLog.configure { |c| c.prefix = '[my logger]' }
|
219
|
-
adapter.send_get_request
|
220
|
-
expect(log).to include("[my logger]")
|
221
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX)
|
222
|
-
end
|
223
|
-
|
224
|
-
it "should log with custom lambda prefix" do
|
225
|
-
HttpLog.configure { |c| c.prefix = -> { '[custom prefix]' } }
|
226
|
-
adapter.send_get_request
|
227
|
-
expect(log).to include("[custom prefix]")
|
228
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
context "POST requests" do
|
233
|
-
if adapter_class.method_defined? :send_post_request
|
234
|
-
it "should not log data if disabled" do
|
235
|
-
HttpLog.configure { |c| c.log_data = false }
|
236
|
-
adapter.send_post_request
|
237
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Data:")
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should not log the response if disabled" do
|
241
|
-
HttpLog.configure { |c| c.log_response = false }
|
242
|
-
adapter.send_post_request
|
243
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Reponse:")
|
244
|
-
end
|
245
|
-
|
246
|
-
it "should prefix all response lines" do
|
247
|
-
HttpLog.configure { |c| c.prefix_response_lines = true }
|
248
|
-
|
249
|
-
adapter.send_post_request
|
250
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Response:")
|
251
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "<html>")
|
252
|
-
end
|
253
|
-
|
254
|
-
it "should prefix all response lines with line numbers" do
|
255
|
-
HttpLog.configure { |c| c.prefix_response_lines = true }
|
256
|
-
HttpLog.configure { |c| c.prefix_line_numbers = true }
|
257
|
-
|
258
|
-
adapter.send_post_request
|
259
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "Response:")
|
260
|
-
expect(log).to include(HttpLog::LOG_PREFIX + "1: <html>")
|
261
|
-
end
|
262
|
-
|
263
|
-
it "should not log the benchmark if disabled" do
|
264
|
-
HttpLog.configure { |c| c.log_benchmark = false }
|
265
|
-
adapter.send_post_request
|
266
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Benchmark:")
|
267
|
-
end
|
268
|
-
|
269
|
-
it "should colorized output" do
|
270
|
-
HttpLog.configure { |c| c.color = :red }
|
271
|
-
adapter.send_post_request
|
272
|
-
expect(log.colorized?).to be_truthy
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
context "POST form data requests" do
|
278
|
-
if adapter_class.method_defined? :send_post_form_request
|
279
|
-
it "should not log data if disabled" do
|
280
|
-
HttpLog.configure { |c| c.log_data = false }
|
281
|
-
adapter.send_post_form_request
|
282
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Data:")
|
283
|
-
end
|
284
|
-
|
285
|
-
it "should not log the response if disabled" do
|
286
|
-
HttpLog.configure { |c| c.log_response = false }
|
287
|
-
adapter.send_post_form_request
|
288
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Reponse:")
|
289
|
-
end
|
290
|
-
|
291
|
-
it "should not log the benchmark if disabled" do
|
292
|
-
HttpLog.configure { |c| c.log_benchmark = false }
|
293
|
-
adapter.send_post_form_request
|
294
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Benchmark:")
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
context "POST multi-part requests (file upload)" do
|
300
|
-
let(:upload) { Tempfile.new('http-log') }
|
301
|
-
let(:params) { {'foo' => 'bar', 'file' => upload} }
|
302
|
-
|
303
|
-
if adapter_class.method_defined? :send_multipart_post_request
|
304
|
-
it "should not log data if disabled" do
|
305
|
-
HttpLog.configure { |c| c.log_data = false }
|
306
|
-
adapter.send_multipart_post_request
|
307
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Data:")
|
308
|
-
end
|
309
|
-
|
310
|
-
it "should not log the response if disabled" do
|
311
|
-
HttpLog.configure { |c| c.log_response = false }
|
312
|
-
adapter.send_multipart_post_request
|
313
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Reponse:")
|
314
|
-
end
|
315
|
-
|
316
|
-
it "should not log the benchmark if disabled" do
|
317
|
-
HttpLog.configure { |c| c.log_benchmark = false }
|
318
|
-
adapter.send_multipart_post_request
|
319
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Benchmark:")
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
context "with compact config" do
|
326
|
-
before(:each) { HttpLog.configure { |c| c.compact_log = true } }
|
327
|
-
|
328
|
-
it "should log a single line with status and benchmark" do
|
329
|
-
adapter.send_get_request
|
330
|
-
expect(log).to match /\[httplog\] GET http:\/\/#{host}:#{port}#{path}(\?.*)? completed with status code \d{3} in (\d|\.)+/
|
331
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Connecting: #{host}:#{port}")
|
332
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Response:")
|
333
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Data:")
|
334
|
-
expect(log).to_not include(HttpLog::LOG_PREFIX + "Benchmark: ")
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
=begin # NOTE: dropping this in v0.99.0 to support ruby 2.4.0. log4r has been stale for years.
|
339
|
-
context "with log4r" do
|
340
|
-
|
341
|
-
before(:each) do
|
342
|
-
require 'log4r'
|
343
|
-
require 'log4r/yamlconfigurator'
|
344
|
-
require 'log4r/outputter/datefileoutputter'
|
345
|
-
log4r_config= YAML.load_file(File.join(File.dirname(__FILE__),"support/log4r.yml"))
|
346
|
-
Log4r::YamlConfigurator.decode_yaml( log4r_config['log4r_config'] )
|
347
|
-
HttpLog.configure{ |c| c.logger = Log4r::Logger['test'] }
|
348
|
-
end
|
349
|
-
|
350
|
-
it "works" do
|
351
|
-
expect { adapter.send_get_request }.to_not raise_error
|
352
|
-
end
|
353
|
-
end
|
354
|
-
=end
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
end
|