http-dump 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +128 -0
- data/Rakefile +7 -0
- data/http-dump.gemspec +25 -0
- data/lib/http-dump.rb +72 -0
- data/lib/http-dump/enable.rb +4 -0
- data/lib/http-dump/version.rb +3 -0
- data/spec/http-dump_spec.rb +71 -0
- data/spec/spec_helper.rb +3 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f4792be8c38ab35c3649ca1976fa69c8e6fa9d8a
|
4
|
+
data.tar.gz: 809025f18e2bb8b5cb6f8cfcebc6464e80d94379
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f1120bb2718f23493c8198040c06f5c443005d68c5bd4c723aa4376f80ca9fea73ab9f83803501f1a5fbd02053195e38256744661d35d3dd5cc9d2201a4930d8
|
7
|
+
data.tar.gz: 6e2867c32283d1a1b09a14a0afe151fff569b2898b1c4ec498fee28952f9f0afb21cdc3b867e6da8517a030676685c68e9a5166df91730a8c4c04533073bd2a8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Yuichi Tateno
|
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,128 @@
|
|
1
|
+
# HTTPDump
|
2
|
+
|
3
|
+
Dump http request use [WebMock](https://github.com/bblimke/webmock).
|
4
|
+
|
5
|
+
Supported HTTP libraries = [WebMock supported liraries](https://github.com/bblimke/webmock#supported-http-libraries), Net::HTTP, HTTPParty, HTTPClient, Excon, more...
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
### HTTPDump.dump(options={}, &block)
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'net/http'
|
13
|
+
require 'uri'
|
14
|
+
require 'http-dump'
|
15
|
+
|
16
|
+
HTTPDump.dump {
|
17
|
+
Net::HTTP.get(URI('http://example.com'))
|
18
|
+
}
|
19
|
+
```
|
20
|
+
|
21
|
+
#### result
|
22
|
+
|
23
|
+
```
|
24
|
+
> GET http://example.com/ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'example.com', 'User-Agent'=>'Ruby'}
|
25
|
+
< 200 OK
|
26
|
+
< Accept-Ranges: bytes
|
27
|
+
< Cache-Control: max-age=604800
|
28
|
+
< Content-Type: text/html
|
29
|
+
< Date: Fri, 03 Jan 2014 13:42:51 GMT
|
30
|
+
< Etag: "359670651"
|
31
|
+
< Expires: Fri, 10 Jan 2014 13:42:51 GMT
|
32
|
+
< Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
|
33
|
+
< Server: ECS (sjc/4FB4)
|
34
|
+
< X-Cache: HIT
|
35
|
+
< X-Ec-Custom-Error: 1
|
36
|
+
< Content-Length: 1270
|
37
|
+
<
|
38
|
+
<!doctype html>
|
39
|
+
<html>
|
40
|
+
<head>
|
41
|
+
<title>Example Domain</title>
|
42
|
+
... more ...
|
43
|
+
```
|
44
|
+
|
45
|
+
### HTTPDump.enable!(options={}), disable!(options={})
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'open-uri'
|
49
|
+
require 'http-dump'
|
50
|
+
|
51
|
+
HTTPDump.enable!
|
52
|
+
open(‘http://example.com’).read
|
53
|
+
HTTPDump.disable!
|
54
|
+
```
|
55
|
+
|
56
|
+
#### result
|
57
|
+
|
58
|
+
```
|
59
|
+
> GET http://example.com/ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'example.com', 'User-Agent'=>'Ruby'}
|
60
|
+
< 200 OK
|
61
|
+
... more ...
|
62
|
+
```
|
63
|
+
|
64
|
+
### HTTPDump.quiet_format
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
HTTPDump.quiet_format = true
|
68
|
+
HTTPDump.dump {
|
69
|
+
Net::HTTP.get(URI('http://example.com'))
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
73
|
+
#### result
|
74
|
+
|
75
|
+
```
|
76
|
+
> GET http://example.com/ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'example.com', 'User-Agent'=>'Ruby'}
|
77
|
+
< 200 OK
|
78
|
+
< Accept-Ranges: bytes
|
79
|
+
< Cache-Control: max-age=604800
|
80
|
+
< Content-Type: text/html
|
81
|
+
< Date: Fri, 03 Jan 2014 14:06:43 GMT
|
82
|
+
< Etag: "359670651"
|
83
|
+
< Expires: Fri, 10 Jan 2014 14:06:43 GMT
|
84
|
+
< Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
|
85
|
+
< Server: ECS (sjc/4FB4)
|
86
|
+
< X-Cache: HIT
|
87
|
+
< X-Ec-Custom-Error: 1
|
88
|
+
< Content-Length: 1270
|
89
|
+
<
|
90
|
+
<!doctype html>
|
91
|
+
* ... Response body is 1270 bytes.
|
92
|
+
</html>
|
93
|
+
|
94
|
+
```
|
95
|
+
|
96
|
+
### HTTPDump.output=, output
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
HTTPDump.output #=> #<IO:<STDOUT>> (default output)
|
100
|
+
HTTPDump.output = STDERR
|
101
|
+
HTTPDump.dump {
|
102
|
+
Net::HTTP.get(URI('http://example.com')) # dump to STDERR
|
103
|
+
}
|
104
|
+
```
|
105
|
+
|
106
|
+
### http-dump/enable
|
107
|
+
|
108
|
+
```sh
|
109
|
+
$ ruby -r'net/http' -r'uri' -r'http-dump/enable' -e 'Net::HTTP.get(URI("http://example.com/"))'
|
110
|
+
> GET http://example.com/ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'example.com', 'User-Agent'=>'Ruby'}
|
111
|
+
< 200 OK
|
112
|
+
...
|
113
|
+
```
|
114
|
+
|
115
|
+
## Installation
|
116
|
+
|
117
|
+
Add this line to your application's Gemfile:
|
118
|
+
|
119
|
+
gem 'http-dump'
|
120
|
+
|
121
|
+
And then execute:
|
122
|
+
|
123
|
+
$ bundle
|
124
|
+
|
125
|
+
Or install it yourself as:
|
126
|
+
|
127
|
+
$ gem install http-dump
|
128
|
+
|
data/Rakefile
ADDED
data/http-dump.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'http-dump/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "http-dump"
|
8
|
+
spec.version = HTTPDump::VERSION
|
9
|
+
spec.authors = ["Yuichi Tateno"]
|
10
|
+
spec.email = ["hotchpotch@gmail.com"]
|
11
|
+
spec.summary = %q{Dump http request use WebMock.}
|
12
|
+
spec.description = %q{Dump http request use WebMock.}
|
13
|
+
spec.homepage = "https://github.com/hotchpotch/http-dump"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_dependency "webmock"
|
22
|
+
spec.add_development_dependency "rspec", '~> 2.14'
|
23
|
+
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
data/lib/http-dump.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
require "http-dump/version"
|
3
|
+
require 'webmock'
|
4
|
+
|
5
|
+
class HTTPDump
|
6
|
+
class << self
|
7
|
+
attr_accessor :output, :quiet_format
|
8
|
+
def enable!(options = {})
|
9
|
+
WebMock.enable!(options)
|
10
|
+
WebMock.allow_net_connect!(options)
|
11
|
+
WebMock.after_request do |request_signature, response|
|
12
|
+
output.puts self.format(request_signature, response)
|
13
|
+
end
|
14
|
+
@enabled = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def disable!(options = {})
|
18
|
+
WebMock.reset_callbacks
|
19
|
+
WebMock.disable_net_connect!(options)
|
20
|
+
WebMock.disable!(options)
|
21
|
+
@enabled = false
|
22
|
+
end
|
23
|
+
|
24
|
+
def dump(options = {}, &block)
|
25
|
+
enabled = @enabled
|
26
|
+
enable!(options) unless enabled
|
27
|
+
block.call
|
28
|
+
ensure
|
29
|
+
disable!(options) unless enabled
|
30
|
+
end
|
31
|
+
|
32
|
+
def output
|
33
|
+
@output || STDOUT
|
34
|
+
end
|
35
|
+
|
36
|
+
def format(request_signature, response)
|
37
|
+
res = []
|
38
|
+
res << "> #{request_signature}"
|
39
|
+
res << "< #{response.status.join(' ')}"
|
40
|
+
response.headers.each {|key, val| res << "< #{key}: #{val}" } if response.headers
|
41
|
+
body = response.body
|
42
|
+
unless body.empty?
|
43
|
+
res << "<"
|
44
|
+
if quiet_format && body.size > 100
|
45
|
+
head = body[0..50]
|
46
|
+
res << head.split("\n")[0]
|
47
|
+
res << "* ... Response body is #{body.bytesize} bytes."
|
48
|
+
tail = body[-50..-1]
|
49
|
+
res << tail.split("\n")[-1]
|
50
|
+
else
|
51
|
+
res << body
|
52
|
+
end
|
53
|
+
end
|
54
|
+
res.join("\n")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
__END__
|
60
|
+
|
61
|
+
#HTTPDump.enable!
|
62
|
+
require 'open-uri'
|
63
|
+
HTTPDump.quiet_formatt = true
|
64
|
+
HTTPDump.dump {
|
65
|
+
open('http://example.com').read
|
66
|
+
}
|
67
|
+
open('http://example.com').read
|
68
|
+
|
69
|
+
HTTPDump.dump {
|
70
|
+
open('http://b.hatena.ne.jp/').read
|
71
|
+
}
|
72
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'uri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
describe HTTPDump do
|
7
|
+
let!(:output) { StringIO.new }
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
HTTPDump.disable!
|
11
|
+
HTTPDump.output = output
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:each) do
|
15
|
+
HTTPDump.quiet_format = false
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have a version' do
|
19
|
+
expect(HTTPDump::VERSION).to be
|
20
|
+
end
|
21
|
+
|
22
|
+
context '.dump' do
|
23
|
+
it 'http://example.com/' do
|
24
|
+
stub_request(:get, 'http://example.com/').to_return({:body => 'EXAMPLE!', :status => 200}).times(2)
|
25
|
+
output.should_receive(:puts).with(/X-My-Header.*foo.*200.*EXAMPLE!/m).once
|
26
|
+
HTTPDump.dump {
|
27
|
+
open('http://example.com/', "X-My-Header" => "foo").read
|
28
|
+
}
|
29
|
+
open('http://example.com/', "X-My-Header" => "foo").read
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'http://example.com/ use Net::HTTP.get' do
|
33
|
+
stub_request(:get, 'http://example.com/').to_return({:body => 'EXAMPLE!', :status => 200}).times(2)
|
34
|
+
output.should_receive(:puts).with(/200.*EXAMPLE!/m).once
|
35
|
+
HTTPDump.dump {
|
36
|
+
Net::HTTP.get(URI('http://example.com/'))
|
37
|
+
}
|
38
|
+
Net::HTTP.get(URI('http://example.com/'))
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'http://example.com/ with quiet_format' do
|
42
|
+
HTTPDump.quiet_format = true
|
43
|
+
stub_request(:get, 'http://example.com/').to_return({:body => 'A' * 10000, :status => 200}).times(1)
|
44
|
+
output.should_receive(:puts).with(/10000/m).once
|
45
|
+
HTTPDump.dump {
|
46
|
+
open('http://example.com/', "X-My-Header" => "foo").read
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it '.enable!' do
|
52
|
+
HTTPDump.enable!
|
53
|
+
HTTPDump.should_not_receive(:enable!)
|
54
|
+
HTTPDump.should_not_receive(:disable!)
|
55
|
+
|
56
|
+
stub_request(:get, 'http://example.com/').to_return({:body => 'EXAMPLE!', :status => 200}).times(2)
|
57
|
+
output.should_receive(:puts).with(/X-My-Header.*foo.*200.*EXAMPLE!/m).twice
|
58
|
+
HTTPDump.dump {
|
59
|
+
open('http://example.com/', "X-My-Header" => "foo").read
|
60
|
+
}
|
61
|
+
open('http://example.com/', "X-My-Header" => "foo").read
|
62
|
+
end
|
63
|
+
|
64
|
+
it '.disable!' do
|
65
|
+
HTTPDump.enable!
|
66
|
+
HTTPDump.disable!
|
67
|
+
stub_request(:get, 'http://example.com/').to_return({:body => 'EXAMPLE!', :status => 200}).times(1)
|
68
|
+
output.should_not_receive(:puts).with(/X-My-Header.*foo.*200.*EXAMPLE!/m)
|
69
|
+
open('http://example.com/', "X-My-Header" => "foo").read
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http-dump
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuichi Tateno
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webmock
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Dump http request use WebMock.
|
70
|
+
email:
|
71
|
+
- hotchpotch@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- http-dump.gemspec
|
84
|
+
- lib/http-dump.rb
|
85
|
+
- lib/http-dump/enable.rb
|
86
|
+
- lib/http-dump/version.rb
|
87
|
+
- spec/http-dump_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://github.com/hotchpotch/http-dump
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.0
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Dump http request use WebMock.
|
113
|
+
test_files:
|
114
|
+
- spec/http-dump_spec.rb
|
115
|
+
- spec/spec_helper.rb
|