sniffer 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +24 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +23 -0
- data/.github/workflows/rspec.yml +37 -0
- data/.github/workflows/rubocop.yml +23 -0
- data/.rubocop.yml +14 -20
- data/CHANGELOG.md +16 -2
- data/README.md +53 -9
- data/docker-compose.yml +18 -0
- data/lib/all_prepend.rb +10 -0
- data/lib/curb_prepend.rb +9 -0
- data/lib/ethon_prepend.rb +9 -0
- data/lib/eventmachine_prepend.rb +9 -0
- data/lib/excon_prepend.rb +9 -0
- data/lib/http_prepend.rb +9 -0
- data/lib/httpclient_prepend.rb +9 -0
- data/lib/net_http_prepend.rb +9 -0
- data/lib/patron_prepend.rb +9 -0
- data/lib/sniffer/adapters/curb_adapter.rb +46 -12
- data/lib/sniffer/adapters/ethon_adapter.rb +53 -31
- data/lib/sniffer/adapters/eventmachine_adapter.rb +74 -38
- data/lib/sniffer/adapters/excon_adapter.rb +60 -30
- data/lib/sniffer/adapters/http_adapter.rb +22 -10
- data/lib/sniffer/adapters/httpclient_adapter.rb +68 -36
- data/lib/sniffer/adapters/net_http_adapter.rb +60 -29
- data/lib/sniffer/adapters/patron_adapter.rb +62 -30
- data/lib/sniffer/config.rb +12 -0
- data/lib/sniffer/data.rb +0 -2
- data/lib/sniffer/data_item.rb +29 -16
- data/lib/sniffer/middleware/chain.rb +73 -0
- data/lib/sniffer/middleware/entry.rb +19 -0
- data/lib/sniffer/middleware/logger.rb +27 -0
- data/lib/sniffer/version.rb +1 -1
- data/lib/sniffer.rb +12 -3
- data/sniffer.gemspec +5 -5
- metadata +38 -22
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25c004fd4e29948699cec6a077433d3b0d98f3571c361be81c4f15626f2143a3
|
4
|
+
data.tar.gz: f08cbb6c16a3d572a3536c2a08eff0978f87e4f4d35b489d4cbfdf3ea60c6af9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9548307ea9f504e05ce9fa1f789a1e0d697906841f34a317f5c67c3e1c0ae669f69afab0537fe5e331550e10b531016227ff68321c1f4eadb4bc3f3d6d7a896b
|
7
|
+
data.tar.gz: 1cacd254ba99b6167c4d2221061ebbba0cb2565c281fe100df31190ac0e37035c14e008544d5f2f02b980a08609187841886d700354c6e76a95cd31afb84781e
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: aderyabin
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
## What did you do?
|
11
|
+
|
12
|
+
## What did you expect to happen?
|
13
|
+
|
14
|
+
## What actually happened?
|
15
|
+
|
16
|
+
## Additional context
|
17
|
+
|
18
|
+
## Environment
|
19
|
+
|
20
|
+
**Ruby Version:**
|
21
|
+
|
22
|
+
**Framework Version (Rails, whatever):**
|
23
|
+
|
24
|
+
**Sniffer Version:**
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
title: ''
|
5
|
+
labels: enhancement
|
6
|
+
assignees: aderyabin
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
## Is your feature request related to a problem? Please describe.
|
11
|
+
|
12
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
13
|
+
|
14
|
+
## Describe the solution you'd like
|
15
|
+
|
16
|
+
A clear and concise description of what you want to happen.
|
17
|
+
|
18
|
+
## Describe alternatives you've considered
|
19
|
+
|
20
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
21
|
+
|
22
|
+
## Additional context
|
23
|
+
|
24
|
+
Add any other context or screenshots about the feature request here.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<!--
|
2
|
+
First of all, thanks for contributing!
|
3
|
+
|
4
|
+
If it's a typo fix or minor documentation update feel free to skip the rest of this template!
|
5
|
+
-->
|
6
|
+
|
7
|
+
## What is the purpose of this pull request?
|
8
|
+
|
9
|
+
<!--
|
10
|
+
If it's a bug fix, then link it to the issue, for example:
|
11
|
+
|
12
|
+
Fixes #xxx
|
13
|
+
-->
|
14
|
+
|
15
|
+
## What changes did you make? (overview)
|
16
|
+
|
17
|
+
## Is there anything you'd like reviewers to focus on?
|
18
|
+
|
19
|
+
## Checklist
|
20
|
+
|
21
|
+
- [ ] I've added tests for this change
|
22
|
+
- [ ] I've added a Changelog entry
|
23
|
+
- [ ] I've updated a documentation
|
@@ -0,0 +1,37 @@
|
|
1
|
+
name: Run Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
rspec:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
ruby-version: ['3.1', '3.0', '2.7', '2.6', '2.5']
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby-version }}
|
22
|
+
- name: Install Bundler
|
23
|
+
run: |
|
24
|
+
gem install bundler
|
25
|
+
- name: Install deps
|
26
|
+
run: |
|
27
|
+
sudo apt-get update
|
28
|
+
sudo apt-get install -y --no-install-recommends libcurl4-openssl-dev
|
29
|
+
- name: Install Ruby deps
|
30
|
+
run: |
|
31
|
+
bundle install --jobs 4 --retry 3
|
32
|
+
- name: Run RSpec
|
33
|
+
run: |
|
34
|
+
bundle exec rspec
|
35
|
+
- name: Run RSpec (prepended)
|
36
|
+
run: |
|
37
|
+
bundle exec rspec -r all_prepend
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: Lint Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
rubocop:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v1
|
14
|
+
- name: Set up Ruby 2.6
|
15
|
+
uses: actions/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 2.6.x
|
18
|
+
- name: Install RuboCop
|
19
|
+
run: |
|
20
|
+
gem install rubocop
|
21
|
+
- name: Run RuboCop
|
22
|
+
run: |
|
23
|
+
rubocop -c .rubocop.yml
|
data/.rubocop.yml
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
2
3
|
# Include gemspec and Rakefile
|
3
4
|
Include:
|
4
|
-
-
|
5
|
-
-
|
6
|
-
-
|
5
|
+
- "lib/**/*.rb"
|
6
|
+
- "lib/**/*.rake"
|
7
|
+
- "spec/**/*.rb"
|
7
8
|
Exclude:
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
-
|
9
|
+
- "bin/**/*"
|
10
|
+
- "Gemfile"
|
11
|
+
- "Rakefile"
|
12
|
+
- "*.gemspec"
|
12
13
|
DisplayCopNames: true
|
13
14
|
StyleGuideCopsOnly: false
|
14
|
-
TargetRubyVersion: 2.4
|
15
15
|
|
16
16
|
Naming/AccessorMethodName:
|
17
17
|
Enabled: false
|
@@ -24,14 +24,14 @@ Style/TrivialAccessors:
|
|
24
24
|
|
25
25
|
Style/Documentation:
|
26
26
|
Exclude:
|
27
|
-
-
|
27
|
+
- "spec/**/*.rb"
|
28
28
|
|
29
29
|
Style/StringLiterals:
|
30
30
|
Enabled: false
|
31
31
|
|
32
32
|
Style/BlockDelimiters:
|
33
33
|
Exclude:
|
34
|
-
-
|
34
|
+
- "spec/**/*.rb"
|
35
35
|
|
36
36
|
Style/DoubleNegation:
|
37
37
|
Enabled: false
|
@@ -47,22 +47,16 @@ Lint/AmbiguousBlockAssociation:
|
|
47
47
|
|
48
48
|
Metrics/MethodLength:
|
49
49
|
Exclude:
|
50
|
-
-
|
50
|
+
- "spec/**/*.rb"
|
51
51
|
|
52
|
-
|
52
|
+
Layout/LineLength:
|
53
53
|
Max: 120
|
54
54
|
Exclude:
|
55
|
-
-
|
55
|
+
- "spec/**/*.rb"
|
56
56
|
|
57
57
|
Metrics/BlockLength:
|
58
58
|
Exclude:
|
59
|
-
-
|
60
|
-
|
61
|
-
Rails/Date:
|
62
|
-
Enabled: false
|
63
|
-
|
64
|
-
Rails/TimeZone:
|
65
|
-
Enabled: false
|
59
|
+
- "spec/**/*.rb"
|
66
60
|
|
67
61
|
Security/YAMLLoad:
|
68
62
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
-
## 0.
|
1
|
+
## 0.5.0 (May 6, 2022) ##
|
2
|
+
|
3
|
+
* Added prepend of all adapters by [@nate-at-gusto](https://github.com/nate-at-gusto)
|
4
|
+
* Replaced `active_attr` to `dry-initializer`
|
5
|
+
* Added rubies `2.7`, `3.0`, `3.1` support
|
6
|
+
|
7
|
+
|
8
|
+
## 0.4.0 (March 19, 2020) ##
|
9
|
+
|
10
|
+
* Added middleware support by [@dsalahutdinov](https://github.com/dsalahutdinov)
|
11
|
+
|
12
|
+
|
13
|
+
## 0.3.2 (January 12, 2018) ##
|
14
|
+
|
15
|
+
* Fix EventMachine::HttpClient not defined in Thin
|
2
16
|
|
3
17
|
## 0.2.0 (January 8, 2018) ##
|
4
18
|
|
5
19
|
* Added Excon adapter
|
6
|
-
* Added EventMachine adapter
|
20
|
+
* Added EventMachine adapter
|
7
21
|
* Added `rotate` option
|
8
22
|
* Added storage capacity feature
|
9
23
|
* Added ruby 2.2 support
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Sniffer
|
2
2
|
|
3
|
-
[](https://github.com/aderyabin/sniffer/actions) [](https://rubygems.org/gems/sniffer) [](https://gitter.im/aderyabin/sniffer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
4
|
|
5
5
|
Sniffer aims to help:
|
6
6
|
|
@@ -19,10 +19,6 @@ Sniffer supports most common HTTP accessing libraries:
|
|
19
19
|
* [EM-HTTP-Request](https://github.com/igrigorik/em-http-request)
|
20
20
|
* [Excon](https://github.com/excon/excon)
|
21
21
|
|
22
|
-
|
23
|
-
<a href="https://evilmartians.com/">
|
24
|
-
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
|
25
|
-
|
26
22
|
## Demo
|
27
23
|
|
28
24
|

|
@@ -35,6 +31,20 @@ Add this line to your application's Gemfile:
|
|
35
31
|
gem 'sniffer'
|
36
32
|
```
|
37
33
|
|
34
|
+
If you wish Sniffer to use `Module#prepend` instead of `alias_method`, you can cause individual adapters to use `prepend` instead with:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
gem 'sniffer', require: ['http_prepend', 'httpclient_prepend', 'sniffer']
|
38
|
+
```
|
39
|
+
|
40
|
+
It's important that `'sniffer'` is the last item in the list. See the `lib` directory for a list of prependable adapters.
|
41
|
+
|
42
|
+
If you want all adapters to use `prepend`:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem 'sniffer', require: ['all_prepend', 'sniffer']
|
46
|
+
```
|
47
|
+
|
38
48
|
And then execute:
|
39
49
|
|
40
50
|
$ bundle
|
@@ -125,8 +135,8 @@ Sniffer default options:
|
|
125
135
|
|
126
136
|
```ruby
|
127
137
|
Sniffer.config do |c|
|
128
|
-
c.logger = Logger.new($stdout)
|
129
|
-
c.severity = Logger::Severity::DEBUG
|
138
|
+
c.logger = Logger.new($stdout)
|
139
|
+
c.severity = Logger::Severity::DEBUG
|
130
140
|
# HTTP options to log
|
131
141
|
c.log = {
|
132
142
|
request_url: true,
|
@@ -137,8 +147,8 @@ Sniffer.config do |c|
|
|
137
147
|
response_headers: true,
|
138
148
|
response_body: true,
|
139
149
|
timing: true
|
140
|
-
}
|
141
|
-
c.store = true
|
150
|
+
}
|
151
|
+
c.store = true # save requests/responses to Sniffer.data
|
142
152
|
c.enabled = false # Sniffer disabled by default
|
143
153
|
c.url_whitelist = nil
|
144
154
|
c.url_blacklist = nil
|
@@ -177,12 +187,45 @@ Sniffer.data[0].to_h
|
|
177
187
|
# => {{:request=>{:host=>"example.com", ...}}
|
178
188
|
```
|
179
189
|
|
190
|
+
### Middleware
|
191
|
+
|
192
|
+
You can add the middleware to run custom code before/after the sniffed data was logged.
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
Sniffer.middleware do |chain|
|
196
|
+
chain.add MyHook
|
197
|
+
end
|
198
|
+
|
199
|
+
class MyHook
|
200
|
+
def request(data_item)
|
201
|
+
puts "Before work"
|
202
|
+
yield
|
203
|
+
puts "After work"
|
204
|
+
end
|
205
|
+
|
206
|
+
def response(data_item)
|
207
|
+
puts "Before work"
|
208
|
+
yield
|
209
|
+
puts "After work"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
```
|
213
|
+
|
180
214
|
## Development
|
181
215
|
|
182
216
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
183
217
|
|
184
218
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
185
219
|
|
220
|
+
|
221
|
+
## Development (with Docker)
|
222
|
+
|
223
|
+
Get local development environment working and tests running is very easy with docker-compose:
|
224
|
+
```sh
|
225
|
+
docker-compose run app bundle
|
226
|
+
docker-compose run app bundle exec rspec
|
227
|
+
```
|
228
|
+
|
186
229
|
## Contributing
|
187
230
|
|
188
231
|
Bug reports and pull requests are welcome on GitHub at https://github.com/aderyabin/sniffer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -195,6 +238,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/aderya
|
|
195
238
|
* [Stanislav Chereshkevich](https://github.com/dissident)
|
196
239
|
* [Anatoliy Kurichev](https://github.com/russo-matrosso)
|
197
240
|
* [Dmitriy Ivliev](https://github.com/moofkit)
|
241
|
+
* [Nate Berkopec](https://github.com/nate-at-gusto)
|
198
242
|
|
199
243
|
## License
|
200
244
|
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
version: '3.4'
|
2
|
+
|
3
|
+
services:
|
4
|
+
app:
|
5
|
+
image: ruby:latest
|
6
|
+
environment:
|
7
|
+
- BUNDLE_PATH=/bundle
|
8
|
+
- BUNDLE_CONFIG=/app/.bundle/config
|
9
|
+
command: bash
|
10
|
+
working_dir: /app
|
11
|
+
volumes:
|
12
|
+
- .:/app:cached
|
13
|
+
- bundler_data:/bundle
|
14
|
+
tmpfs:
|
15
|
+
- /tmp
|
16
|
+
|
17
|
+
volumes:
|
18
|
+
bundler_data:
|
data/lib/all_prepend.rb
ADDED
data/lib/curb_prepend.rb
ADDED
data/lib/http_prepend.rb
ADDED
@@ -4,16 +4,6 @@ module Sniffer
|
|
4
4
|
module Adapters
|
5
5
|
# Curl adapter
|
6
6
|
module CurlAdapter
|
7
|
-
def self.included(base)
|
8
|
-
base.class_eval do
|
9
|
-
alias_method :http_without_sniffer, :http
|
10
|
-
alias_method :http, :http_with_sniffer
|
11
|
-
|
12
|
-
alias_method :http_post_without_sniffer, :http_post
|
13
|
-
alias_method :http_post, :http_post_with_sniffer
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
7
|
def http_with_sniffer(verb)
|
18
8
|
sniffer_request(verb)
|
19
9
|
|
@@ -40,6 +30,37 @@ module Sniffer
|
|
40
30
|
@res
|
41
31
|
end
|
42
32
|
|
33
|
+
# Only used when prepending, see all_prepend.rb
|
34
|
+
module Prepend
|
35
|
+
include CurlAdapter
|
36
|
+
|
37
|
+
def http(verb)
|
38
|
+
sniffer_request(verb)
|
39
|
+
|
40
|
+
super(verb)
|
41
|
+
|
42
|
+
bm = Benchmark.realtime do
|
43
|
+
@res = super(verb)
|
44
|
+
end
|
45
|
+
|
46
|
+
sniffer_response(bm)
|
47
|
+
|
48
|
+
@res
|
49
|
+
end
|
50
|
+
|
51
|
+
def http_post(*args)
|
52
|
+
sniffer_request(:POST, *args)
|
53
|
+
|
54
|
+
bm = Benchmark.realtime do
|
55
|
+
@res = super(*args)
|
56
|
+
end
|
57
|
+
|
58
|
+
sniffer_response(bm)
|
59
|
+
|
60
|
+
@res
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
43
64
|
private
|
44
65
|
|
45
66
|
def data_item
|
@@ -76,10 +97,23 @@ module Sniffer
|
|
76
97
|
body: body_str,
|
77
98
|
timing: timing)
|
78
99
|
|
79
|
-
data_item
|
100
|
+
Sniffer.notify_response(data_item)
|
80
101
|
end
|
81
102
|
end
|
82
103
|
end
|
83
104
|
end
|
84
105
|
|
85
|
-
|
106
|
+
if defined?(::Curl::Easy)
|
107
|
+
if defined?(Sniffer::Adapters::CurlAdapter::PREPEND)
|
108
|
+
Curl::Easy.prepend Sniffer::Adapters::CurlAdapter::Prepend
|
109
|
+
else
|
110
|
+
Curl::Easy.class_eval do
|
111
|
+
include Sniffer::Adapters::CurlAdapter
|
112
|
+
alias_method :http_without_sniffer, :http
|
113
|
+
alias_method :http, :http_with_sniffer
|
114
|
+
|
115
|
+
alias_method :http_post_without_sniffer, :http_post
|
116
|
+
alias_method :http_post, :http_post_with_sniffer
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|