marcopolo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/lib/marcopolo.rb +21 -0
- data/lib/marcopolo/middleware.rb +49 -0
- data/lib/marcopolo/rails.rb +7 -0
- data/lib/marcopolo/version.rb +3 -0
- data/marcopolo.gemspec +23 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 273c7f6bc3a4dc54e700b022bf0d079789f23ee2
|
4
|
+
data.tar.gz: c38e36b80fe9b021019a66e6d47ebdbb80553157
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc4bf97a33318d3df0cfcc456048bf8fd262a728a354c53d244febd31b3b87883dc146a92639f1d84b34f4d2736407d20559eddf5aa7510712d985d4efc8228e
|
7
|
+
data.tar.gz: 42199344fafdb02820dc276bf15f1fe1eb44b064819612690798461595a61de86b3e8ae608dc2fb06c25a97056e45b7c0d801fdaff2d58fd3b9370c1e73f26f7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Andrew Hammond
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Marcopolo
|
2
|
+
|
3
|
+
Marcopolo is a Rack middleware for use in Rails applications (currently) to aid in debugging HTTP requests and responses by logging them *raw* (including headers and body).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'marcopolo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
By simply including the gem in your Gemfile, your Rails app will automatically start logging raw incoming HTTP requests and your app's responses to your Rails log. That being said, you can choose a different log location if you wish.
|
18
|
+
|
19
|
+
Configure the logger settings in a Rails initializer like so:
|
20
|
+
|
21
|
+
Marcopolo.options[:logger] = Logger.new(File.join(Rails.root, 'log', "#{Rails.env}-http-raw.log"))
|
22
|
+
Marcopolo.options[:severity] = Logger::Severity::DEBUG
|
23
|
+
|
24
|
+
Consider adding logrote rules to your application server to prevent these extremely verbose logs from blowing up your storage.
|
25
|
+
|
26
|
+
Also, be mindful of cleaning up these logs appropriately, as sensative information like authorization headers and cookies will not be filtered out automatically (hence "raw").
|
27
|
+
|
28
|
+
## TODO
|
29
|
+
|
30
|
+
* Support for Sinatra?
|
31
|
+
* Noise filters?
|
32
|
+
* Ability to disable for certain endpoints, etc
|
33
|
+
* IP-based log segmenting?
|
34
|
+
* Tests?
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it ( http://github.com/<my-github-username>/marcopolo/fork )
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/marcopolo.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "marcopolo/version"
|
2
|
+
require 'marcopolo/middleware'
|
3
|
+
require 'marcopolo/rails' if defined?(Rails)
|
4
|
+
|
5
|
+
module Marcopolo
|
6
|
+
DEFAULT_LOGGER = Logger.new($stdout)
|
7
|
+
DEFAULT_OPTIONS = {
|
8
|
+
logger: DEFAULT_LOGGER,
|
9
|
+
severity: Logger::Severity::DEBUG
|
10
|
+
}
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def options
|
14
|
+
@@options ||= DEFAULT_OPTIONS.clone
|
15
|
+
end
|
16
|
+
|
17
|
+
def log(msg)
|
18
|
+
options[:logger].add(options[:severity]) { msg }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Marcopolo
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
req = Rack::Request.new(env)
|
9
|
+
|
10
|
+
req_headers = env.select {|k,v| k.start_with? 'HTTP_'}
|
11
|
+
.collect {|pair| [pair[0].sub(/^HTTP_/, '').split('_').map(&:titleize).join('-'), pair[1]]}
|
12
|
+
.sort
|
13
|
+
|
14
|
+
req_hash = {
|
15
|
+
"REQUEST" => "",
|
16
|
+
"Remote Address" => req.ip,
|
17
|
+
"Request URL" => req.url,
|
18
|
+
"Request Method" => req.request_method,
|
19
|
+
"REQUEST HEADERS" => ""
|
20
|
+
}
|
21
|
+
|
22
|
+
req_headers.to_a.each {|i| req_hash["\t" + i.first] = i.last }
|
23
|
+
|
24
|
+
req_hash.merge!({
|
25
|
+
"Request Body" => req.body.gets
|
26
|
+
})
|
27
|
+
|
28
|
+
Marcopolo.log req_hash.to_a.map {|o| o.join(': ') }.join("\n") + "\n"
|
29
|
+
|
30
|
+
status, headers, response = @app.call(env)
|
31
|
+
|
32
|
+
resp_hash = {
|
33
|
+
"RESPONSE" => "",
|
34
|
+
"Response Status" => response.status,
|
35
|
+
"Response Headers" => ""
|
36
|
+
}
|
37
|
+
|
38
|
+
response.headers.to_a.each {|i| resp_hash["\t" + i.first] = i.last }
|
39
|
+
|
40
|
+
resp_hash.merge!({
|
41
|
+
"Response Body" => response.body
|
42
|
+
})
|
43
|
+
|
44
|
+
Marcopolo.log resp_hash.to_a.map {|o| o.join(': ') }.join("\n") + "\n"
|
45
|
+
|
46
|
+
return [status, headers, response]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/marcopolo.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'marcopolo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "marcopolo"
|
8
|
+
spec.version = Marcopolo::VERSION
|
9
|
+
spec.authors = ["Andrew Hammond"]
|
10
|
+
spec.email = ["andrew@evertrue.com"]
|
11
|
+
spec.summary = %q{Log raw HTTP requests & responses}
|
12
|
+
spec.description = %q{Log raw HTTP requests & responses}
|
13
|
+
spec.homepage = "http://github.com/andrhamm"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marcopolo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Hammond
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Log raw HTTP requests & responses
|
42
|
+
email:
|
43
|
+
- andrew@evertrue.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/marcopolo.rb
|
54
|
+
- lib/marcopolo/middleware.rb
|
55
|
+
- lib/marcopolo/rails.rb
|
56
|
+
- lib/marcopolo/version.rb
|
57
|
+
- marcopolo.gemspec
|
58
|
+
homepage: http://github.com/andrhamm
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.2.0
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Log raw HTTP requests & responses
|
82
|
+
test_files: []
|
83
|
+
has_rdoc:
|