httplog 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -7
- data/httplog.gemspec +3 -2
- data/lib/httplog/adapters/ethon.rb +33 -15
- data/lib/httplog/configuration.rb +1 -1
- data/lib/httplog/http_log.rb +2 -1
- data/lib/httplog/version.rb +1 -1
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b45410a66dcec431137326ea3402d5f7aa46aec70ad5bd826dc3fe24021c4dfe
|
4
|
+
data.tar.gz: a7fb94896bd9456ca53f83c78a9b0ed025e9dffd537bf531b56350488334ee1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4abf19d31bcf87d0f4f5cdf4eab1eee36f1974581310077be364a3a89d9f5dae956b7cd5fa021b2711606ac6657ce904a293119a3da8738d95e45d52fc98d50b
|
7
|
+
data.tar.gz: 567406b24ed46bf14bec3960ad246c8ca866f9f96160fcb3578c99969548d2720a5dde179eb69ac129c787cd9121839560914900bd9eef7f68986cd545c93438
|
data/README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
## httplog
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/httplog.svg)](http://badge.fury.io/rb/httplog) [![Build Status](https://travis-ci.
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/httplog.svg)](http://badge.fury.io/rb/httplog) [![Build Status](https://travis-ci.com/trusche/httplog.svg?branch=master)](https://travis-ci.org/trusche/httplog) [![Code Climate](https://codeclimate.com/github/trusche/httplog.svg)](https://codeclimate.com/github/trusche/httplog)
|
4
4
|
[![Release Version](https://img.shields.io/github/release/trusche/httplog.svg)](https://img.shields.io/github/release/trusche/httplog.svg)
|
5
|
-
<a href="https://www.bearer.sh?ref=httplog"><img src="/bearer-badge.png" height="20px"/></a>
|
6
5
|
|
7
6
|
Log outgoing HTTP requests made from your application. Helps with debugging pesky API error responses, or just generally understanding what's going on under the hood.
|
8
7
|
|
9
|
-
Requires ruby >= 2.
|
8
|
+
Requires ruby >= 2.6
|
10
9
|
|
11
10
|
This gem works with the following ruby modules and libraries:
|
12
11
|
|
@@ -30,10 +29,6 @@ This is very much a development and debugging tool; it is **not recommended** to
|
|
30
29
|
use this in a production environment as it is monkey-patching the respective HTTP implementations.
|
31
30
|
You have been warned - use at your own risk.
|
32
31
|
|
33
|
-
Httplog is kindly sponsored by <a href="https://www.bearer.sh?ref=httplog">Bearer.sh</a> - go check them out please!
|
34
|
-
|
35
|
-
<a href="https://www.bearer.sh?ref=httplog"><img src="/bearer-sponsor.png" height="72px" /></a>
|
36
|
-
|
37
32
|
### Installation
|
38
33
|
|
39
34
|
gem install httplog
|
data/httplog.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.test_files = `git ls-files -- test/*`.split("\n")
|
23
23
|
gem.require_paths = ['lib']
|
24
24
|
|
25
|
-
gem.required_ruby_version = '>= 2.
|
25
|
+
gem.required_ruby_version = '>= 2.6'
|
26
26
|
|
27
27
|
gem.add_development_dependency 'ethon', ['~> 0.11']
|
28
28
|
gem.add_development_dependency 'excon', ['~> 0.60']
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |gem|
|
|
32
32
|
gem.add_development_dependency 'httparty', ['~> 0.16']
|
33
33
|
gem.add_development_dependency 'httpclient', ['~> 2.8']
|
34
34
|
gem.add_development_dependency 'rest-client', ['~> 2.0']
|
35
|
+
gem.add_development_dependency 'typhoeus', ['~> 1.4']
|
35
36
|
gem.add_development_dependency 'listen', ['~> 3.0']
|
36
37
|
gem.add_development_dependency 'patron', ['~> 0.12']
|
37
38
|
gem.add_development_dependency 'rake', ['~> 13.0']
|
@@ -40,6 +41,6 @@ Gem::Specification.new do |gem|
|
|
40
41
|
gem.add_development_dependency 'thin', ['~> 1.7']
|
41
42
|
gem.add_development_dependency 'oj', ['>= 3.9.2']
|
42
43
|
|
43
|
-
gem.add_dependency 'rack', ['>=
|
44
|
+
gem.add_dependency 'rack', ['>= 2.0']
|
44
45
|
gem.add_dependency 'rainbow', ['>= 2.0.0']
|
45
46
|
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 = options.merge(method: action_name) # remember this for compact logging
|
11
|
+
@http_log = options.merge(method: action_name, url: url) # remember this for compact logging
|
12
12
|
orig_http_request(url, action_name, options)
|
13
13
|
end
|
14
14
|
end
|
@@ -18,32 +18,50 @@ if defined?(Ethon)
|
|
18
18
|
def perform
|
19
19
|
return orig_perform unless HttpLog.url_approved?(url)
|
20
20
|
|
21
|
-
|
21
|
+
httplog_add_callback
|
22
22
|
|
23
|
-
|
24
|
-
# extract it from the response header.
|
25
|
-
encoding = response_headers.scan(/Content-Encoding: (\S+)/).flatten.first
|
26
|
-
content_type = response_headers.scan(/Content-Type: (\S+(; charset=\S+)?)/).flatten.first
|
23
|
+
bm = Benchmark.realtime { orig_perform }
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
headers = response_headers.split(/\r?\n/).drop(1)
|
25
|
+
url = @http_log[:url]
|
26
|
+
url = "#{url}?#{@http_log[:params]}" if @http_log[:params]
|
31
27
|
|
32
28
|
HttpLog.call(
|
33
29
|
method: @http_log[:method],
|
34
|
-
url:
|
30
|
+
url: url,
|
35
31
|
request_body: @http_log[:body],
|
36
32
|
request_headers: @http_log[:headers],
|
37
33
|
response_code: @return_code,
|
38
|
-
response_body: response_body,
|
39
|
-
response_headers:
|
34
|
+
response_body: @http_log[:response_body],
|
35
|
+
response_headers: @http_log[:response_headers].map { |header| header.split(/:\s/) }.to_h,
|
40
36
|
benchmark: bm,
|
41
|
-
encoding: encoding,
|
42
|
-
content_type: content_type,
|
43
|
-
mask_body: HttpLog.masked_body_url?(url)
|
37
|
+
encoding: @http_log[:encoding],
|
38
|
+
content_type: @http_log[:content_type],
|
39
|
+
mask_body: HttpLog.masked_body_url?(@http_log[:url])
|
44
40
|
)
|
45
41
|
return_code
|
46
42
|
end
|
43
|
+
|
44
|
+
def httplog_add_callback
|
45
|
+
# Hack to perform this callback before the cleanup
|
46
|
+
@on_complete ||= []
|
47
|
+
@on_complete.unshift -> (*) do
|
48
|
+
# Not sure where the actual status code is stored - so let's
|
49
|
+
# extract it from the response header.
|
50
|
+
encoding = response_headers.scan(/Content-Encoding: (\S+)/).flatten.first
|
51
|
+
content_type = response_headers.scan(/Content-Type: (\S+(; charset=\S+)?)/).flatten.first
|
52
|
+
|
53
|
+
# Hard to believe that Ethon wouldn't parse out the headers into
|
54
|
+
# an array; probably overlooked it. Anyway, let's do it ourselves:
|
55
|
+
headers = response_headers.split(/\r?\n/).drop(1)
|
56
|
+
|
57
|
+
@http_log.merge!(
|
58
|
+
encoding: encoding,
|
59
|
+
content_type: content_type,
|
60
|
+
response_headers: headers,
|
61
|
+
response_body: response_body
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
47
65
|
end
|
48
66
|
end
|
49
67
|
end
|
data/lib/httplog/http_log.rb
CHANGED
@@ -26,6 +26,7 @@ module HttpLog
|
|
26
26
|
|
27
27
|
def configure
|
28
28
|
yield(configuration)
|
29
|
+
configuration.json_parser ||= ::JSON if configuration.json_log || configuration.url_masked_body_pattern
|
29
30
|
end
|
30
31
|
|
31
32
|
def call(options = {})
|
@@ -349,7 +350,7 @@ module HttpLog
|
|
349
350
|
end
|
350
351
|
|
351
352
|
def log_data_lines(data)
|
352
|
-
data.each_line.with_index do |line, row|
|
353
|
+
data.to_s.each_line.with_index do |line, row|
|
353
354
|
if config.prefix_line_numbers
|
354
355
|
log("#{row + 1}: #{line.chomp}")
|
355
356
|
else
|
data/lib/httplog/version.rb
CHANGED
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.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thilo Rusche
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ethon
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '2.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: typhoeus
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.4'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.4'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: listen
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,14 +240,14 @@ dependencies:
|
|
226
240
|
requirements:
|
227
241
|
- - ">="
|
228
242
|
- !ruby/object:Gem::Version
|
229
|
-
version: '
|
243
|
+
version: '2.0'
|
230
244
|
type: :runtime
|
231
245
|
prerelease: false
|
232
246
|
version_requirements: !ruby/object:Gem::Requirement
|
233
247
|
requirements:
|
234
248
|
- - ">="
|
235
249
|
- !ruby/object:Gem::Version
|
236
|
-
version: '
|
250
|
+
version: '2.0'
|
237
251
|
- !ruby/object:Gem::Dependency
|
238
252
|
name: rainbow
|
239
253
|
requirement: !ruby/object:Gem::Requirement
|
@@ -281,14 +295,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
281
295
|
requirements:
|
282
296
|
- - ">="
|
283
297
|
- !ruby/object:Gem::Version
|
284
|
-
version: '2.
|
298
|
+
version: '2.6'
|
285
299
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
286
300
|
requirements:
|
287
301
|
- - ">="
|
288
302
|
- !ruby/object:Gem::Version
|
289
303
|
version: '0'
|
290
304
|
requirements: []
|
291
|
-
rubygems_version: 3.
|
305
|
+
rubygems_version: 3.3.7
|
292
306
|
signing_key:
|
293
307
|
specification_version: 4
|
294
308
|
summary: Log outgoing HTTP requests.
|