README.md in sniffer-0.3.2 vs README.md in sniffer-0.4.0
- old
+ new
@@ -1,8 +1,8 @@
# Sniffer
-[![Build Status](https://travis-ci.org/aderyabin/sniffer.svg?branch=master)](https://travis-ci.org/aderyabin/sniffer) [![Gem Version](https://badge.fury.io/rb/sniffer.svg)](https://rubygems.org/gems/sniffer) [![Join the chat at https://gitter.im/aderyabin/sniffer](https://badges.gitter.im/aderyabin/sniffer.svg)](https://gitter.im/aderyabin/sniffer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+[![Build](https://github.com/aderyabin/sniffer/workflows/Run%20Tests/badge.svg)](https://github.com/aderyabin/sniffer/actions) [![Gem Version](https://badge.fury.io/rb/sniffer.svg)](https://rubygems.org/gems/sniffer) [![Join the chat at https://gitter.im/aderyabin/sniffer](https://badges.gitter.im/aderyabin/sniffer.svg)](https://gitter.im/aderyabin/sniffer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Sniffer aims to help:
* Log outgoing HTTP requests. Sniffer logs as JSON format for export to ELK, Logentries and etc.
* Debug requests. Sniffer allows to save all requests/responses in storage for future debugging
@@ -17,14 +17,10 @@
* [Ethon](https://github.com/typhoeus/ethon)
* [Typhoeus](https://github.com/typhoeus/typhoeus)
* [EM-HTTP-Request](https://github.com/igrigorik/em-http-request)
* [Excon](https://github.com/excon/excon)
-
-<a href="https://evilmartians.com/">
-<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
-
## Demo
![demo](https://github.com/aderyabin/sniffer/blob/master/assets/demo.gif?raw=true)
## Installation
@@ -123,24 +119,24 @@
Sniffer default options:
```ruby
Sniffer.config do |c|
- c.logger = Logger.new($stdout),
- c.severity = Logger::Severity::DEBUG,
+ c.logger = Logger.new($stdout)
+ c.severity = Logger::Severity::DEBUG
# HTTP options to log
c.log = {
request_url: true,
request_headers: true,
request_body: true,
request_method: true,
response_status: true,
response_headers: true,
response_body: true,
timing: true
- },
- c.store = true, # save requests/responses to Sniffer.data
+ }
+ c.store = true # save requests/responses to Sniffer.data
c.enabled = false # Sniffer disabled by default
c.url_whitelist = nil
c.url_blacklist = nil
end
```
@@ -173,9 +169,33 @@
# => {}
HTTP.get('http://example.com')
Sniffer.data[0].to_h
# => {{:request=>{:host=>"example.com", ...}}
+```
+
+### Middleware
+
+You can add the middleware to run custom code before/after the sniffed data was logged.
+
+```ruby
+Sniffer.middleware do |chain|
+ chain.add MyHook
+end
+
+class MyHook
+ def request(data_item)
+ puts "Before work"
+ yield
+ puts "After work"
+ end
+
+ def response(data_item)
+ puts "Before work"
+ yield
+ puts "After work"
+ end
+end
```
## Development
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.