httplog 1.5.0 → 1.6.1
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 +9 -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 +24 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0741018e32c5c27fcd5af3f417806ccd01f0034ce67083d90ddf13812ba5d8e5'
|
4
|
+
data.tar.gz: bb0dadfbbd7e3834a1a99459e3828c5cc11c04624ae194f488209b417f75880e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 024403ade01a1e3fd8352735f65c61ee5d723a914be3cae1b57e6f66498e37fc4234424ed7ab51f7d79f9d536080bd978046a913eb3ead713b5c46c0920582b2
|
7
|
+
data.tar.gz: d4004322b6371d761f9c6e4868b7a71943f166935c53a59c42af902ac1666d7e4c279d8fc24e3b1b8b7009cc3301a9e783775e07a3bdee513dc23839757f25da
|
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
@@ -17,12 +17,18 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.description = "Log outgoing HTTP requests made from your application. Helpful for tracking API calls
|
18
18
|
of third party gems that don't provide their own log output."
|
19
19
|
|
20
|
+
gem.metadata = {
|
21
|
+
"bug_tracker_uri" => "https://github.com/trusche/httplog/issues",
|
22
|
+
"changelog_uri" => "https://github.com/trusche/httplog/CHANGELOG.md",
|
23
|
+
"source_code_uri" => "https://github.com/trusche/httplog"
|
24
|
+
}
|
25
|
+
|
20
26
|
gem.files = Dir['lib/**/*.rb'] +
|
21
27
|
%w(httplog.gemspec README.md CHANGELOG.md)
|
22
28
|
gem.test_files = `git ls-files -- test/*`.split("\n")
|
23
29
|
gem.require_paths = ['lib']
|
24
30
|
|
25
|
-
gem.required_ruby_version = '>= 2.
|
31
|
+
gem.required_ruby_version = '>= 2.6'
|
26
32
|
|
27
33
|
gem.add_development_dependency 'ethon', ['~> 0.11']
|
28
34
|
gem.add_development_dependency 'excon', ['~> 0.60']
|
@@ -32,6 +38,7 @@ Gem::Specification.new do |gem|
|
|
32
38
|
gem.add_development_dependency 'httparty', ['~> 0.16']
|
33
39
|
gem.add_development_dependency 'httpclient', ['~> 2.8']
|
34
40
|
gem.add_development_dependency 'rest-client', ['~> 2.0']
|
41
|
+
gem.add_development_dependency 'typhoeus', ['~> 1.4']
|
35
42
|
gem.add_development_dependency 'listen', ['~> 3.0']
|
36
43
|
gem.add_development_dependency 'patron', ['~> 0.12']
|
37
44
|
gem.add_development_dependency 'rake', ['~> 13.0']
|
@@ -40,6 +47,6 @@ Gem::Specification.new do |gem|
|
|
40
47
|
gem.add_development_dependency 'thin', ['~> 1.7']
|
41
48
|
gem.add_development_dependency 'oj', ['>= 3.9.2']
|
42
49
|
|
43
|
-
gem.add_dependency 'rack', ['>=
|
50
|
+
gem.add_dependency 'rack', ['>= 2.0']
|
44
51
|
gem.add_dependency 'rainbow', ['>= 2.0.0']
|
45
52
|
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.1
|
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-11-19 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
|
@@ -272,7 +286,10 @@ files:
|
|
272
286
|
homepage: http://github.com/trusche/httplog
|
273
287
|
licenses:
|
274
288
|
- MIT
|
275
|
-
metadata:
|
289
|
+
metadata:
|
290
|
+
bug_tracker_uri: https://github.com/trusche/httplog/issues
|
291
|
+
changelog_uri: https://github.com/trusche/httplog/CHANGELOG.md
|
292
|
+
source_code_uri: https://github.com/trusche/httplog
|
276
293
|
post_install_message:
|
277
294
|
rdoc_options: []
|
278
295
|
require_paths:
|
@@ -281,14 +298,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
281
298
|
requirements:
|
282
299
|
- - ">="
|
283
300
|
- !ruby/object:Gem::Version
|
284
|
-
version: '2.
|
301
|
+
version: '2.6'
|
285
302
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
286
303
|
requirements:
|
287
304
|
- - ">="
|
288
305
|
- !ruby/object:Gem::Version
|
289
306
|
version: '0'
|
290
307
|
requirements: []
|
291
|
-
rubygems_version: 3.
|
308
|
+
rubygems_version: 3.3.7
|
292
309
|
signing_key:
|
293
310
|
specification_version: 4
|
294
311
|
summary: Log outgoing HTTP requests.
|