http_logger 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ee612be76637a3fa5e75db03b7fa33a7016d3b4f509c32295580e002df73bd2
4
- data.tar.gz: f7ef81b6d4c9d61dfa37626794a6bb725c1e83b36b29d824bf70bd5215bfb4e8
3
+ metadata.gz: e8cd08ba96dbddfa8f11e4bcbebb2cdde1bc99c19a2603eb2253c1f48d173214
4
+ data.tar.gz: 0c11b8553de5807f784dd14276017a5b8b7bf6d393e296fb246835bcc6fa0b78
5
5
  SHA512:
6
- metadata.gz: 9d81717a77786fb2bffb89c9cce68bc1f9ef8c6d4f2960a945324db0c53831cd8c78643e3c21779f1250cf862e2dcaa5a3d6610eb5fb934c2a15ed296225c416
7
- data.tar.gz: 90132a5f50f91d39542f255680e577bd755254815df1f5332d71c73db76eadc2862a30d9b43dfc04e6cb50ce7aea30dc5143997c41a3c3cff07616eea342b285
6
+ metadata.gz: 3b3bcc69fac4c32215adfa5dac3ba2c0312d67b51a7e6890349bb007a3508f1b91b1b8284c1d835684319e39af6045d2945d8703d43347e130abedffd81bf0fb
7
+ data.tar.gz: 1a0d722184351705fedb9245f0b74ee2fa315a3df44b956db9561b30bf69b3bce337d179d0f82cb9142239754dd2d2fb363101c1497b85111721079c5b42e1f3
data/Gemfile CHANGED
@@ -1,9 +1,11 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  group :development do
4
+ gem "rake"
4
5
  gem "byebug"
5
6
  gem "webmock"
6
7
  gem "rspec"
8
+ gem "bump", "~> 0.10.0"
7
9
  gem "bundler"
8
- gem "jeweler"
9
10
  end
11
+
data/Gemfile.lock CHANGED
@@ -2,85 +2,42 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  addressable (2.4.0)
5
- builder (3.2.4)
6
- byebug (11.1.1)
7
- crack (0.4.3)
8
- safe_yaml (~> 1.0.0)
9
- descendants_tracker (0.0.4)
10
- thread_safe (~> 0.3, >= 0.3.1)
11
- diff-lcs (1.3)
12
- faraday (0.9.2)
13
- multipart-post (>= 1.2, < 3)
14
- git (1.5.0)
15
- github_api (0.16.0)
16
- addressable (~> 2.4.0)
17
- descendants_tracker (~> 0.0.4)
18
- faraday (~> 0.8, < 0.10)
19
- hashie (>= 3.4)
20
- mime-types (>= 1.16, < 3.0)
21
- oauth2 (~> 1.0)
22
- hashdiff (1.0.0)
23
- hashie (4.0.0)
24
- highline (2.0.3)
25
- jeweler (2.3.9)
26
- builder
27
- bundler
28
- git (>= 1.2.5)
29
- github_api (~> 0.16.0)
30
- highline (>= 1.6.15)
31
- nokogiri (>= 1.5.10)
32
- psych
33
- rake
34
- rdoc
35
- semver2
36
- jwt (2.2.1)
37
- mime-types (2.99.3)
38
- mini_portile2 (2.4.0)
39
- multi_json (1.14.1)
40
- multi_xml (0.6.0)
41
- multipart-post (2.1.1)
42
- nokogiri (1.10.7)
43
- mini_portile2 (~> 2.4.0)
44
- oauth2 (1.4.2)
45
- faraday (>= 0.8, < 2.0)
46
- jwt (>= 1.0, < 3.0)
47
- multi_json (~> 1.3)
48
- multi_xml (~> 0.5)
49
- rack (>= 1.2, < 3)
50
- psych (3.1.0)
51
- rack (2.1.1)
52
- rake (13.0.1)
53
- rdoc (6.2.1)
54
- rspec (3.9.0)
55
- rspec-core (~> 3.9.0)
56
- rspec-expectations (~> 3.9.0)
57
- rspec-mocks (~> 3.9.0)
58
- rspec-core (3.9.1)
59
- rspec-support (~> 3.9.1)
60
- rspec-expectations (3.9.0)
5
+ bump (0.10.0)
6
+ byebug (11.1.3)
7
+ crack (0.4.5)
8
+ rexml
9
+ diff-lcs (1.4.4)
10
+ hashdiff (1.0.1)
11
+ rake (13.0.6)
12
+ rexml (3.2.5)
13
+ rspec (3.10.0)
14
+ rspec-core (~> 3.10.0)
15
+ rspec-expectations (~> 3.10.0)
16
+ rspec-mocks (~> 3.10.0)
17
+ rspec-core (3.10.1)
18
+ rspec-support (~> 3.10.0)
19
+ rspec-expectations (3.10.1)
61
20
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.9.0)
63
- rspec-mocks (3.9.1)
21
+ rspec-support (~> 3.10.0)
22
+ rspec-mocks (3.10.2)
64
23
  diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.9.0)
66
- rspec-support (3.9.2)
67
- safe_yaml (1.0.5)
68
- semver2 (3.4.2)
69
- thread_safe (0.3.6)
70
- webmock (3.8.0)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-support (3.10.3)
26
+ webmock (3.13.0)
71
27
  addressable (>= 2.3.6)
72
28
  crack (>= 0.3.2)
73
29
  hashdiff (>= 0.4.0, < 2.0.0)
74
30
 
75
31
  PLATFORMS
76
- ruby
32
+ x86_64-darwin-19
77
33
 
78
34
  DEPENDENCIES
35
+ bump (~> 0.10.0)
79
36
  bundler
80
37
  byebug
81
- jeweler
38
+ rake
82
39
  rspec
83
40
  webmock
84
41
 
85
42
  BUNDLED WITH
86
- 2.0.1
43
+ 2.2.22
data/Rakefile CHANGED
@@ -9,24 +9,13 @@ rescue Bundler::BundlerError => e
9
9
  $stderr.puts "Run `bundle install` to install missing gems"
10
10
  exit e.status_code
11
11
  end
12
- require 'rake'
13
12
 
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "http_logger"
18
- gem.homepage = "http://github.com/railsware/http_logger"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Log your http api calls just like SQL queries}
21
- gem.description = %Q{This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file}
22
- gem.email = "agresso@gmail.com"
23
- gem.authors = ["Bogdan Gusiev"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
13
+ require 'rake'
14
+ require 'bundler/gem_tasks'
27
15
 
28
16
  require 'rspec/core'
29
17
  require 'rspec/core/rake_task'
18
+
30
19
  RSpec::Core::RakeTask.new(:spec) do |spec|
31
20
  spec.pattern = FileList['spec/**/*_spec.rb']
32
21
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.0
data/http_logger.gemspec CHANGED
@@ -1,12 +1,12 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: http_logger 0.6.0 ruby lib
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "http_logger/version"
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "http_logger".freeze
9
- s.version = "0.6.0"
9
+ s.version = HttpLogger::VERSION
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
data/lib/http_logger.rb CHANGED
@@ -22,6 +22,8 @@ require 'set'
22
22
  #
23
23
  # cat /tmp/all.log
24
24
  class HttpLogger
25
+ AUTHORIZATION_HEADER = 'Authorization'
26
+
25
27
  class << self
26
28
  attr_accessor :collapse_body_limit
27
29
  attr_accessor :log_headers
@@ -82,10 +84,17 @@ class HttpLogger
82
84
 
83
85
  def log_request_headers(request)
84
86
  if self.class.log_headers
85
- request.each_capitalized { |k,v| log("HTTP request header", "#{k}: #{v}") }
87
+ request.each_capitalized do |k,v|
88
+ log_header(:request, k, v)
89
+ end
86
90
  end
87
91
  end
88
92
 
93
+ def log_header(type, name, value)
94
+ value = "<filtered>" if name == AUTHORIZATION_HEADER
95
+ log("HTTP #{type} header", "#{name}: #{value}")
96
+ end
97
+
89
98
  HTTP_METHODS_WITH_BODY = Set.new(%w(POST PUT GET PATCH))
90
99
 
91
100
  def log_request_body(request)
@@ -104,7 +113,9 @@ class HttpLogger
104
113
 
105
114
  def log_response_headers(response)
106
115
  if HttpLogger.log_headers
107
- response.each_capitalized { |k,v| log("HTTP response header", "#{k}: #{v}") }
116
+ response.each_capitalized do |k,v|
117
+ log_header(:response, k, v)
118
+ end
108
119
  end
109
120
  end
110
121
 
@@ -121,7 +132,8 @@ class HttpLogger
121
132
  end
122
133
 
123
134
  def require_logging?(http, request)
124
- self.logger && !ignored?(http, request) && (http.started? || fakeweb?(http, request))
135
+
136
+ self.logger && !ignored?(http, request) && (http.started? || webmock?(http, request))
125
137
  end
126
138
 
127
139
  def ignored?(http, request)
@@ -131,7 +143,7 @@ class HttpLogger
131
143
  end
132
144
  end
133
145
 
134
- def fakeweb?(http, request)
146
+ def webmock?(http, request)
135
147
  return false unless defined?(::WebMock)
136
148
  uri = request_uri_as_string(http, request)
137
149
  method = request.method.downcase.to_sym
@@ -146,8 +158,8 @@ class HttpLogger
146
158
  path = URI.parse(request.path).request_uri if request.path =~ /^http/
147
159
 
148
160
  if request["authorization"] =~ /^Basic /
149
- userinfo = FakeWeb::Utility.decode_userinfo_from_header(request["authorization"])
150
- userinfo = FakeWeb::Utility.encode_unsafe_chars_in_userinfo(userinfo) + "@"
161
+ userinfo = WebMock::Utility.decode_userinfo_from_header(request["authorization"])
162
+ userinfo = WebMock::Utility.encode_unsafe_chars_in_userinfo(userinfo) + "@"
151
163
  else
152
164
  userinfo = ""
153
165
  end
@@ -190,27 +202,28 @@ class HttpLogger
190
202
  end
191
203
  end
192
204
 
193
- module NetHttpLogger
205
+ block = lambda do |a|
206
+ # raise instance_methods.inspect
207
+ alias request_without_net_http_logger request
194
208
  def request(request, body = nil, &block)
195
209
  HttpLogger.perform(self, request, body) do
196
- super(request, body, &block)
210
+ request_without_net_http_logger(request, body, &block)
197
211
  end
212
+
198
213
  end
199
214
  end
200
215
 
201
216
  if defined?(::WebMock)
202
- WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get("@webMockNetHTTP").prepend(NetHttpLogger)
217
+ klass = WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get("@webMockNetHTTP")
218
+ # raise klass.instance_methods.inspect
219
+ klass.class_eval(&block)
203
220
  end
204
- Net::HTTP.prepend(NetHttpLogger)
205
221
 
206
- if defined?(Rails)
207
222
 
208
- if !Rails.respond_to?(:application) || (Rails.application && Rails.application.config)
209
- # Rails2
210
- Rails.configuration.after_initialize do
211
- HttpLogger.logger = Rails.logger unless HttpLogger.logger
212
- end
213
- elsif defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)
223
+ Net::HTTP.class_eval(&block)
224
+
225
+ if defined?(Rails)
226
+ if defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)
214
227
  # Rails3
215
228
  ActiveSupport.on_load(:after_initialize) do
216
229
  HttpLogger.logger = Rails.logger unless HttpLogger.logger
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require "uri"
3
+ require "base64"
3
4
 
4
5
  describe HttpLogger do
5
6
 
@@ -9,16 +10,18 @@ describe HttpLogger do
9
10
  f.close
10
11
  stub_request(:any, url).to_return(
11
12
  body: response_body,
12
- headers: {"X-Http-logger" => true},
13
+ headers: {"X-Http-logger" => true, **response_headers},
13
14
  )
14
15
  end
15
16
 
16
17
  let(:response_body) { "Success" }
18
+ let(:response_headers) { {} }
19
+ let(:request_headers) { {} }
17
20
 
18
21
  let(:url) { "http://google.com/" }
19
22
  let(:uri) { URI.parse(url) }
20
23
  let(:request) do
21
- Net::HTTP.get_response(uri)
24
+ Net::HTTP.get_response(uri, **request_headers)
22
25
  end
23
26
 
24
27
  let(:long_body) do
@@ -51,6 +54,15 @@ describe HttpLogger do
51
54
  it { should include("HTTP response header") }
52
55
  it { should include("HTTP request header") }
53
56
 
57
+
58
+ context "authorization header" do
59
+
60
+ let(:request_headers) do
61
+ {'Authorization' => "Basic #{Base64.encode64('hello:world')}".strip}
62
+ end
63
+ it { should include("Authorization: <filtered>") }
64
+ end
65
+
54
66
  after(:each) do
55
67
  HttpLogger.log_headers = false
56
68
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-01-27 00:00:00.000000000 Z
@@ -107,7 +107,7 @@ homepage: http://github.com/railsware/http_logger
107
107
  licenses:
108
108
  - MIT
109
109
  metadata: {}
110
- post_install_message:
110
+ post_install_message:
111
111
  rdoc_options: []
112
112
  require_paths:
113
113
  - lib
@@ -122,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  requirements: []
125
- rubyforge_project:
126
- rubygems_version: 2.7.8
127
- signing_key:
125
+ rubygems_version: 3.2.22
126
+ signing_key:
128
127
  specification_version: 4
129
128
  summary: Log your http api calls just like SQL queries
130
129
  test_files: []