httplog 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/httplog.gemspec +1 -2
- data/lib/httplog/adapters/ethon.rb +2 -3
- data/lib/httplog/adapters/excon.rb +3 -3
- data/lib/httplog/adapters/http.rb +4 -5
- data/lib/httplog/http_log.rb +3 -3
- data/lib/httplog/version.rb +1 -1
- data/spec/support/shared_examples.rb +2 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9395e3bb51404b12d1d3504e928ae722793de10c
|
4
|
+
data.tar.gz: a365c1134ff32ec56eb14f0fd26ac9b971269e1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2a020f5b5e3d7796cf37194e7e77942ffe4f39e6d2ec2319d5c25e1d18ee62780240397df4e71407a5bfd45d04835fce02cfefb3731a19bcad10bcf5965196e
|
7
|
+
data.tar.gz: 9c5dda03458471e2fa64b1853c2b0ddd08820802268dc4c4681de322b008912f2e79a100525135f2b2282939ef157bc4618ac21b178589d8987316747640e460
|
data/Gemfile.lock
CHANGED
data/httplog.gemspec
CHANGED
@@ -37,7 +37,6 @@ Gem::Specification.new do |gem|
|
|
37
37
|
gem.add_development_dependency 'simplecov', ['~> 0.15']
|
38
38
|
gem.add_development_dependency 'thin', ['~> 1.7']
|
39
39
|
|
40
|
-
# gem.add_dependency 'colorize', ['~> 0.8']
|
41
|
-
gem.add_dependency 'rainbow', ['>= 2.0.0']
|
42
40
|
gem.add_dependency 'rack', ['>= 1.0']
|
41
|
+
gem.add_dependency 'rainbow', ['>= 2.0.0']
|
43
42
|
end
|
@@ -8,7 +8,7 @@ if defined?(Ethon)
|
|
8
8
|
module Http
|
9
9
|
alias orig_http_request http_request
|
10
10
|
def http_request(url, action_name, options = {})
|
11
|
-
@http_log
|
11
|
+
@http_log = options.merge(method: action_name) # remember this for compact logging
|
12
12
|
orig_http_request(url, action_name, options)
|
13
13
|
end
|
14
14
|
end
|
@@ -22,7 +22,6 @@ if defined?(Ethon)
|
|
22
22
|
|
23
23
|
# Not sure where the actual status code is stored - so let's
|
24
24
|
# extract it from the response header.
|
25
|
-
status = response_headers.scan(%r{HTTP/... (\d{3})}).flatten.first
|
26
25
|
encoding = response_headers.scan(/Content-Encoding: (\S+)/).flatten.first
|
27
26
|
content_type = response_headers.scan(/Content-Type: (\S+(; charset=\S+)?)/).flatten.first
|
28
27
|
|
@@ -37,7 +36,7 @@ if defined?(Ethon)
|
|
37
36
|
request_headers: @http_log[:headers],
|
38
37
|
response_code: @return_code,
|
39
38
|
response_body: response_body,
|
40
|
-
response_headers: headers.map{ |header| header.split(/:\s/) }.to_h,
|
39
|
+
response_headers: headers.map { |header| header.split(/:\s/) }.to_h,
|
41
40
|
benchmark: bm,
|
42
41
|
encoding: encoding,
|
43
42
|
content_type: content_type
|
@@ -3,7 +3,7 @@
|
|
3
3
|
if defined?(Excon)
|
4
4
|
module Excon
|
5
5
|
module HttpLogHelper
|
6
|
-
def
|
6
|
+
def httplog_url(datum)
|
7
7
|
@httplog_url ||= "#{datum[:scheme]}://#{datum[:host]}:#{datum[:port]}#{datum[:path]}#{datum[:query]}"
|
8
8
|
end
|
9
9
|
end
|
@@ -14,7 +14,7 @@ if defined?(Excon)
|
|
14
14
|
def connect
|
15
15
|
host = @data[:proxy] ? @data[:proxy][:host] : @data[:host]
|
16
16
|
port = @data[:proxy] ? @data[:proxy][:port] : @data[:port]
|
17
|
-
HttpLog.log_connection(host, port) if ::HttpLog.url_approved?(
|
17
|
+
HttpLog.log_connection(host, port) if ::HttpLog.url_approved?(httplog_url(@data))
|
18
18
|
orig_connect
|
19
19
|
end
|
20
20
|
end
|
@@ -30,7 +30,7 @@ if defined?(Excon)
|
|
30
30
|
result = orig_request(params, &block)
|
31
31
|
end
|
32
32
|
|
33
|
-
url =
|
33
|
+
url = httplog_url(@data)
|
34
34
|
return result unless HttpLog.url_approved?(url)
|
35
35
|
|
36
36
|
headers = result[:headers] || {}
|
@@ -8,18 +8,17 @@ if defined?(::HTTP::Client) && defined?(::HTTP::Connection)
|
|
8
8
|
alias_method(orig_request_method, request_method) unless method_defined?(orig_request_method)
|
9
9
|
|
10
10
|
define_method request_method do |req, options|
|
11
|
-
|
11
|
+
bm = Benchmark.realtime do
|
12
|
+
@response = send(orig_request_method, req, options)
|
13
|
+
end
|
12
14
|
|
15
|
+
if HttpLog.url_approved?(req.uri)
|
13
16
|
body = if defined?(::HTTP::Request::Body)
|
14
17
|
req.body.respond_to?(:source) ? req.body.source : req.body.instance_variable_get(:@body)
|
15
18
|
else
|
16
19
|
req.body
|
17
20
|
end
|
18
21
|
|
19
|
-
bm = Benchmark.realtime do
|
20
|
-
@response = send(orig_request_method, req, options)
|
21
|
-
end
|
22
|
-
|
23
22
|
HttpLog.call(
|
24
23
|
method: req.verb,
|
25
24
|
url: req.uri,
|
data/lib/httplog/http_log.rb
CHANGED
@@ -119,7 +119,7 @@ module HttpLog
|
|
119
119
|
sio = StringIO.new(body.to_s)
|
120
120
|
gz = Zlib::GzipReader.new(sio)
|
121
121
|
body = gz.read
|
122
|
-
rescue Zlib::GzipFile::Error
|
122
|
+
rescue Zlib::GzipFile::Error
|
123
123
|
log("(gzip decompression failed)")
|
124
124
|
end
|
125
125
|
end
|
@@ -178,7 +178,7 @@ module HttpLog
|
|
178
178
|
end
|
179
179
|
|
180
180
|
def transform_response_code(response_code_name)
|
181
|
-
Rack::Utils::HTTP_STATUS_CODES.detect{ |
|
181
|
+
Rack::Utils::HTTP_STATUS_CODES.detect { |_k, v| v.to_s.casecmp(response_code_name.to_s).zero? }.first
|
182
182
|
end
|
183
183
|
|
184
184
|
def colorize(msg)
|
@@ -190,7 +190,7 @@ module HttpLog
|
|
190
190
|
msg = Rainbow(msg).color(config.color)
|
191
191
|
end
|
192
192
|
msg
|
193
|
-
rescue
|
193
|
+
rescue StandardError
|
194
194
|
warn "HTTPLOG CONFIGURATION ERROR: #{config.color} is not a valid color"
|
195
195
|
msg
|
196
196
|
end
|
data/lib/httplog/version.rb
CHANGED
@@ -3,7 +3,7 @@ RSpec.shared_examples 'logs request' do |method|
|
|
3
3
|
it { is_expected.to include(HttpLog::LOG_PREFIX + "Sending: #{method} http://#{host}:#{port}#{path}") }
|
4
4
|
end
|
5
5
|
|
6
|
-
RSpec.shared_examples 'logs nothing' do
|
6
|
+
RSpec.shared_examples 'logs nothing' do
|
7
7
|
subject { log }
|
8
8
|
it { is_expected.to eq('') }
|
9
9
|
end
|
@@ -20,7 +20,7 @@ RSpec.shared_examples 'logs status' do |status|
|
|
20
20
|
it { is_expected.to include(["Status:", status].compact.join(' ')) }
|
21
21
|
end
|
22
22
|
|
23
|
-
RSpec.shared_examples 'logs benchmark' do
|
23
|
+
RSpec.shared_examples 'logs benchmark' do
|
24
24
|
it { is_expected.to match(/Benchmark: \d+\.\d+ seconds/) }
|
25
25
|
end
|
26
26
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httplog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thilo Rusche
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ethon
|
@@ -193,33 +193,33 @@ dependencies:
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '1.7'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
196
|
+
name: rack
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
199
|
- - ">="
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
201
|
+
version: '1.0'
|
202
202
|
type: :runtime
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - ">="
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
208
|
+
version: '1.0'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
|
-
name:
|
210
|
+
name: rainbow
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
213
|
- - ">="
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version:
|
215
|
+
version: 2.0.0
|
216
216
|
type: :runtime
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version:
|
222
|
+
version: 2.0.0
|
223
223
|
description: |-
|
224
224
|
Log outgoing HTTP requests made from your application. Helpful for tracking API calls
|
225
225
|
of third party gems that don't provide their own log output.
|