httplog 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 171da0b013750ec91396725db8f43e91bfaa2044
|
4
|
+
data.tar.gz: 16903e8cc554aff0a9548ce2ee954a1b0cc7217f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c68d8a348d96a068fcc72c53d76a7ff270a9fcb53f5bae5502b3f84cded30f3848f4e8a105208b70467c1ea9b50636604b16ca2849f75d3edc460b19f1c2d829
|
7
|
+
data.tar.gz: 57e537dbd5ae1eb6d0b6fff9ba8e7e8a4c528e20b5b29a7d21157b4a47c3bd94feb7c49bc375ccb79256091704ff7792a0ed40f75378addf8a07b4ddd6e406ce
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
inherit_from: ./.rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.2
|
5
|
+
Exclude:
|
6
|
+
- 'db/**/*'
|
7
|
+
- 'db/schema.rb'
|
8
|
+
- 'app/assets/**'
|
9
|
+
- 'config/**/*'
|
10
|
+
- 'bin/**/*'
|
11
|
+
- 'node_modules/**/*'
|
12
|
+
- 'public/**/*'
|
13
|
+
- 'tmp/**/*'
|
14
|
+
- 'vendor/**/*'
|
15
|
+
- 'doc/**/*'
|
16
|
+
- 'coverage/**/*'
|
17
|
+
- Gemfile
|
18
|
+
- Guardfile
|
19
|
+
|
20
|
+
Layout/EmptyLinesAroundBlockBody:
|
21
|
+
EnforcedStyle: no_empty_lines
|
22
|
+
Enabled: true
|
23
|
+
|
24
|
+
Layout/EmptyLinesAroundClassBody:
|
25
|
+
EnforcedStyle: no_empty_lines
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
Layout/EmptyLinesAroundModuleBody:
|
29
|
+
EnforcedStyle: no_empty_lines
|
30
|
+
|
31
|
+
Layout/IndentArray:
|
32
|
+
EnforcedStyle: consistent
|
33
|
+
|
34
|
+
Style/Documentation:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/Lambda:
|
38
|
+
EnforcedStyle: literal
|
39
|
+
|
40
|
+
Style/PercentLiteralDelimiters:
|
41
|
+
PreferredDelimiters:
|
42
|
+
default: '[]'
|
43
|
+
'%i': '[]'
|
44
|
+
|
45
|
+
Metrics/PerceivedComplexity:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Metrics/CyclomaticComplexity:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
Metrics/ModuleLength:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Metrics/BlockNesting:
|
55
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Offense count: 13
|
2
|
+
Metrics/AbcSize:
|
3
|
+
Enabled: false
|
4
|
+
|
5
|
+
# Offense count: 43
|
6
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
7
|
+
Metrics/BlockLength:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
# Offense count: 137
|
11
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
12
|
+
# URISchemes: http, https
|
13
|
+
Metrics/LineLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
# Offense count: 7
|
17
|
+
# Configuration parameters: CountComments.
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/ClassLength:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
# Offense count: 195
|
25
|
+
# Cop supports --auto-correct.
|
26
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
27
|
+
# SupportedStyles: when_needed, always, never
|
28
|
+
Style/FrozenStringLiteralComment:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
# Offense count: 328
|
32
|
+
# Cop supports --auto-correct.
|
33
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
34
|
+
# SupportedStyles: single_quotes, double_quotes
|
35
|
+
Style/StringLiterals:
|
36
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/Guardfile
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# A sample Guardfile
|
2
4
|
# More info at https://github.com/guard/guard#readme
|
3
5
|
|
4
|
-
guard 'rspec', :
|
6
|
+
guard 'rspec', version: 2 do
|
5
7
|
watch(%r{^spec/.+_spec\.rb$})
|
6
8
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
-
watch('spec/spec_helper.rb') {
|
9
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
8
10
|
|
9
11
|
# Rails example
|
10
12
|
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
13
|
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
14
|
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
-
watch(%r{^spec/support/(.+)\.rb$}) {
|
14
|
-
watch('config/routes.rb') {
|
15
|
-
watch('app/controllers/application_controller.rb') {
|
16
|
-
|
15
|
+
watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
|
16
|
+
watch('config/routes.rb') { 'spec/routing' }
|
17
|
+
watch('app/controllers/application_controller.rb') { 'spec/controllers' }
|
18
|
+
|
17
19
|
# Capybara request specs
|
18
20
|
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
19
|
-
|
21
|
+
|
20
22
|
# Turnip features and steps
|
21
23
|
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
-
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})
|
24
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
25
|
end
|
24
|
-
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
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.
|
6
6
|
|
7
|
-
|
7
|
+
Requires ruby >= 2.2.
|
8
8
|
|
9
9
|
This gem works with the following ruby modules and libraries:
|
10
10
|
|
@@ -128,6 +128,9 @@ With `compact_log` enabled, the same request might look like this:
|
|
128
128
|
|
129
129
|
### Known Issues
|
130
130
|
|
131
|
+
Following are some known quirks and issues with particular libraries. If you know a workaround or have
|
132
|
+
a suggestion for a fix, please open an issue or, even better, submit a pull request!
|
133
|
+
|
131
134
|
* Requests types other than GET and POST have not been explicitly tested.
|
132
135
|
They may or may not be logged, depending on the implementation details of the underlying library.
|
133
136
|
If they are not for a particular library, please feel free to open an issue with the details.
|
@@ -158,6 +161,9 @@ With `compact_log` enabled, the same request might look like this:
|
|
158
161
|
|
159
162
|
* Benchmarking only covers the time between starting the HTTP request and receiving the response. It does *not* cover the time it takes to establish the TCP connection.
|
160
163
|
|
164
|
+
* When using [REST Client](https://github.com/rest-client/rest-client), POST requests might be missing the requests
|
165
|
+
data. See #54 for details.
|
166
|
+
|
161
167
|
### Running the specs
|
162
168
|
|
163
169
|
Make sure you have the necessary dependencies installed by running `bundle install`.
|
data/Rakefile
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
begin
|
3
5
|
require 'bundler/setup'
|
4
6
|
rescue LoadError
|
@@ -13,10 +15,10 @@ rescue LoadError
|
|
13
15
|
end
|
14
16
|
require 'rspec/core/rake_task'
|
15
17
|
|
16
|
-
desc
|
18
|
+
desc 'Run specs'
|
17
19
|
RSpec::Core::RakeTask.new(:spec)
|
18
20
|
|
19
|
-
desc
|
21
|
+
desc 'Generate documentation'
|
20
22
|
RDoc::Task.new(:rdoc) do |rdoc|
|
21
23
|
rdoc.rdoc_dir = 'rdoc'
|
22
24
|
rdoc.title = 'HttpLog'
|
@@ -36,9 +38,9 @@ end
|
|
36
38
|
|
37
39
|
# ----- Packaging -----
|
38
40
|
task :build do
|
39
|
-
sh
|
41
|
+
sh 'gem build httplog.gemspec'
|
40
42
|
mkdir_p 'pkg'
|
41
|
-
sh
|
43
|
+
sh 'mv *.gem pkg/ '
|
42
44
|
end
|
43
45
|
|
44
|
-
task :
|
46
|
+
task default: :spec
|
data/gemfiles/http2.gemfile
CHANGED
data/gemfiles/http3.gemfile
CHANGED
data/gemfiles/http4.gemfile
CHANGED
data/gemfiles/rack1.gemfile
CHANGED
data/gemfiles/rack2.gemfile
CHANGED
data/httplog.gemspec
CHANGED
@@ -1,41 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Provide a simple gemspec so you can easily use your
|
2
4
|
# project in your rails apps through git.
|
3
5
|
|
4
|
-
|
5
|
-
require
|
6
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
7
|
+
require 'httplog/version'
|
6
8
|
|
7
9
|
Gem::Specification.new do |gem|
|
8
|
-
gem.name =
|
10
|
+
gem.name = 'httplog'
|
9
11
|
gem.version = HttpLog::VERSION
|
10
|
-
gem.licenses = [
|
11
|
-
gem.summary =
|
12
|
-
gem.authors = [
|
13
|
-
gem.email =
|
14
|
-
gem.
|
15
|
-
gem.
|
16
|
-
|
17
|
-
of third party gems that don't provide their own log output.}
|
12
|
+
gem.licenses = ['MIT']
|
13
|
+
gem.summary = 'Log outgoing HTTP requests.'
|
14
|
+
gem.authors = ['Thilo Rusche']
|
15
|
+
gem.email = 'thilorusche@gmail.com'
|
16
|
+
gem.homepage = 'http://github.com/trusche/httplog'
|
17
|
+
gem.description = "Log outgoing HTTP requests made from your application. Helpful for tracking API calls
|
18
|
+
of third party gems that don't provide their own log output."
|
18
19
|
|
19
20
|
gem.files = `git ls-files`.split("\n")
|
20
21
|
gem.test_files = `git ls-files -- test/*`.split("\n")
|
21
|
-
gem.require_paths = [
|
22
|
+
gem.require_paths = ['lib']
|
22
23
|
|
23
|
-
gem.required_ruby_version =
|
24
|
+
gem.required_ruby_version = '>= 2.2'
|
24
25
|
|
25
|
-
gem.add_development_dependency
|
26
|
-
gem.add_development_dependency
|
27
|
-
gem.add_development_dependency
|
28
|
-
gem.add_development_dependency
|
29
|
-
gem.add_development_dependency
|
30
|
-
gem.add_development_dependency
|
31
|
-
gem.add_development_dependency
|
32
|
-
gem.add_development_dependency
|
33
|
-
gem.add_development_dependency
|
34
|
-
gem.add_development_dependency
|
35
|
-
gem.add_development_dependency
|
36
|
-
gem.add_development_dependency
|
37
|
-
gem.add_development_dependency
|
26
|
+
gem.add_development_dependency 'ethon', ['~> 0.11']
|
27
|
+
gem.add_development_dependency 'excon', ['~> 0.60']
|
28
|
+
gem.add_development_dependency 'faraday', ['~> 0.14']
|
29
|
+
gem.add_development_dependency 'guard-rspec', ['~> 4.7']
|
30
|
+
gem.add_development_dependency 'http', ['~> 3.0']
|
31
|
+
gem.add_development_dependency 'httparty', ['~> 0.16']
|
32
|
+
gem.add_development_dependency 'httpclient', ['~> 2.8']
|
33
|
+
gem.add_development_dependency 'listen', ['~> 3.0']
|
34
|
+
gem.add_development_dependency 'patron', ['~> 0.12']
|
35
|
+
gem.add_development_dependency 'rake', ['~> 12.3']
|
36
|
+
gem.add_development_dependency 'rspec', ['~> 3.7']
|
37
|
+
gem.add_development_dependency 'simplecov', ['~> 0.15']
|
38
|
+
gem.add_development_dependency 'thin', ['~> 1.7']
|
38
39
|
|
39
|
-
gem.add_dependency
|
40
|
-
gem.add_dependency
|
40
|
+
gem.add_dependency 'colorize', ['~> 0.8']
|
41
|
+
gem.add_dependency 'rack', ['>= 1.0']
|
41
42
|
end
|
data/lib/httplog.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httplog/version'
|
4
|
+
require 'httplog/configuration'
|
5
|
+
require 'httplog/http_log'
|
6
|
+
require 'httplog/adapters/net_http'
|
7
|
+
require 'httplog/adapters/httpclient'
|
8
|
+
require 'httplog/adapters/excon'
|
9
|
+
require 'httplog/adapters/ethon'
|
10
|
+
require 'httplog/adapters/patron'
|
11
|
+
require 'httplog/adapters/http'
|
@@ -1,17 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
if defined?(Ethon)
|
2
4
|
module Ethon
|
3
5
|
class Easy
|
4
|
-
|
5
6
|
attr_accessor :action_name
|
6
7
|
|
7
8
|
module Http
|
8
|
-
|
9
|
+
alias orig_http_request http_request
|
9
10
|
def http_request(url, action_name, options = {})
|
10
11
|
@action_name = action_name # remember this for compact logging
|
11
12
|
if HttpLog.url_approved?(url)
|
12
13
|
HttpLog.log_request(action_name, url)
|
13
14
|
HttpLog.log_headers(options[:headers])
|
14
|
-
HttpLog.log_data(options[:body]) #if action_name == :post
|
15
|
+
HttpLog.log_data(options[:body]) # if action_name == :post
|
15
16
|
end
|
16
17
|
|
17
18
|
orig_http_request(url, action_name, options)
|
@@ -19,18 +20,15 @@ if defined?(Ethon)
|
|
19
20
|
end
|
20
21
|
|
21
22
|
module Operations
|
22
|
-
|
23
|
+
alias orig_perform perform
|
23
24
|
def perform
|
24
25
|
return orig_perform unless HttpLog.url_approved?(url)
|
25
26
|
|
26
|
-
|
27
|
-
bm = Benchmark.realtime do
|
28
|
-
reponse_code = orig_perform
|
29
|
-
end
|
27
|
+
bm = Benchmark.realtime { orig_perform }
|
30
28
|
|
31
29
|
# Not sure where the actual status code is stored - so let's
|
32
30
|
# extract it from the response header.
|
33
|
-
status = response_headers.scan(
|
31
|
+
status = response_headers.scan(%r{HTTP/... (\d{3})}).flatten.first
|
34
32
|
encoding = response_headers.scan(/Content-Encoding: (\S+)/).flatten.first
|
35
33
|
content_type = response_headers.scan(/Content-Type: (\S+(; charset=\S+)?)/).flatten.first
|
36
34
|
|
@@ -1,23 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
if defined?(Excon)
|
2
4
|
module Excon
|
3
5
|
class Socket
|
4
|
-
|
6
|
+
alias orig_connect connect
|
5
7
|
def connect
|
6
8
|
host = @data[:proxy] ? @data[:proxy][:host] : @data[:host]
|
7
9
|
port = @data[:proxy] ? @data[:proxy][:port] : @data[:port]
|
8
10
|
HttpLog.log_connection(host, port)
|
9
11
|
orig_connect
|
10
12
|
end
|
11
|
-
|
12
13
|
end
|
13
14
|
|
14
15
|
class Connection
|
15
|
-
|
16
16
|
def _httplog_url(datum)
|
17
17
|
"#{datum[:scheme]}://#{datum[:host]}:#{datum[:port]}#{datum[:path]}#{datum[:query]}"
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
alias orig_request request
|
21
21
|
def request(params, &block)
|
22
22
|
result = nil
|
23
23
|
bm = Benchmark.realtime do
|
@@ -35,25 +35,23 @@ if defined?(Excon)
|
|
35
35
|
result
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
alias orig_request_call request_call
|
39
39
|
def request_call(datum)
|
40
40
|
url = _httplog_url(datum)
|
41
41
|
|
42
42
|
if HttpLog.url_approved?(url)
|
43
43
|
HttpLog.log_request(datum[:method], _httplog_url(datum))
|
44
44
|
HttpLog.log_headers(datum[:headers])
|
45
|
-
HttpLog.log_data(datum[:body])# if datum[:method] == :post
|
45
|
+
HttpLog.log_data(datum[:body]) # if datum[:method] == :post
|
46
46
|
end
|
47
47
|
orig_request_call(datum)
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
def response(datum={})
|
50
|
+
alias orig_response response
|
51
|
+
def response(datum = {})
|
52
52
|
return orig_response(datum) unless HttpLog.url_approved?(_httplog_url(datum))
|
53
53
|
|
54
|
-
|
55
|
-
datum = orig_response(datum)
|
56
|
-
end
|
54
|
+
datum = orig_response(datum)
|
57
55
|
response = datum[:response]
|
58
56
|
headers = response[:headers] || {}
|
59
57
|
HttpLog.log_status(response[:status])
|