rack_curler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/lib/rack_curler/version.rb +3 -0
- data/lib/rack_curler.rb +44 -0
- data/rack_curler.gemspec +26 -0
- data/spec/rack_curler_spec.rb +161 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGNkNTdlM2QzMGRiZjY1NTM1ODkyZTI0YTQ4ZTEwYjJkZGM0MmYyNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MDg5YTc2ZTU0ZDczYjU3ZmQyNDA5MjRlNzg1MDgzMGJkM2FjMDUzOQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDkwN2E2NjBlYjgzNDkyZWRiZjhkOTk4NGZjYTRlOGRlNWEwNjIzMmVlMWIw
|
10
|
+
N2QzMmM2MDkwZGU5MjY2MWJmMGYxZDY0Zjk0YWU0NjMzOTE0YmM0OGM1Mjc0
|
11
|
+
OWFhNDIwMGY4ODZjNjhmMzlkN2M5MmZiMzNhNWNmZTViMmEwZWE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YzViOTZiYmRmNmM5OTQ2MzU1YjFkY2E1OTIyMDNlYmIyMDU1MDU5MDRiZjVj
|
14
|
+
OWNiNTIxMDMxOGM1NmYxZTZjNmNmZGZmMDRhOGRjZTc2N2NjMDJlZWFmNjA0
|
15
|
+
YTQ2NGIzZmJmZGJjMjZiODc3YTZlOTQyYjFkNzk0MDI4Njk3M2Y=
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rack_curler
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3-p448
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Nathan Speed
|
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
|
+
# RackCurler
|
2
|
+
|
3
|
+
Given a Rack env, generate a nicely formatted curl command that approximates the request. Suitable for debugging.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rack_curler'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rack_curler
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Where ```env``` is a Rack env:
|
22
|
+
|
23
|
+
RackCurler.to_curl(env)
|
24
|
+
|
25
|
+
Will output something like (depending on the request):
|
26
|
+
|
27
|
+
curl 'https://foo.example.com/hello/times' \
|
28
|
+
-X PUT
|
29
|
+
-H 'X-Forwarded-For: 127.0.0.1' \
|
30
|
+
-H 'X-Forwarded-Proto: https' \
|
31
|
+
-H 'Authorization: Basic laiusdfhalnsidufhxalnsuhflsadufhxadlsunxdsauhnlaudflnsuhadsf==' \
|
32
|
+
-H 'Accept: application/json' \
|
33
|
+
-H 'Cookie: crazy_cookie=alskdjfhasldkjfhxalsdufhxwoeufhxa; normal_cookie=asdfsadhfjlkdsajflksadjfh;'
|
34
|
+
--data 'super awesome request body'
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
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/rack_curler.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "rack_curler/version"
|
2
|
+
|
3
|
+
module RackCurler
|
4
|
+
def self.to_curl(env)
|
5
|
+
|
6
|
+
headers_to_drop = [
|
7
|
+
'Version', # make your life easy and let curl set this
|
8
|
+
'Content-Length', # curl will set this for you
|
9
|
+
'Host', # curl will set this for you
|
10
|
+
'Connection', # curl will set this for you
|
11
|
+
'Accept-Encoding', # for debugging, you don't want an encoded-response
|
12
|
+
'Date' # it would be incorrect to repeat
|
13
|
+
]
|
14
|
+
|
15
|
+
header_defaults = {
|
16
|
+
'Accept' => '*/*',
|
17
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
18
|
+
}
|
19
|
+
|
20
|
+
env['rack.input'].rewind
|
21
|
+
body = env['rack.input'].read
|
22
|
+
env['rack.input'].rewind
|
23
|
+
|
24
|
+
headerize = lambda { |raw| raw.split(/[ _\-]/).map(&:capitalize).join('-') }
|
25
|
+
|
26
|
+
headers = {}.tap do |h|
|
27
|
+
env.select { |k, v| k =~ /^HTTP_/ || k == 'CONTENT_TYPE' }
|
28
|
+
.each { |k, v| h[headerize.call(k.sub(/^HTTP_/, ''))] = v}
|
29
|
+
h.select! { |k, v| !headers_to_drop.member?(k) }
|
30
|
+
h.select! { |k, v| header_defaults[k].nil? || header_defaults[k] != v }
|
31
|
+
end
|
32
|
+
|
33
|
+
url = Rack::Request.new(env).url
|
34
|
+
|
35
|
+
curl_command = "curl '#{url}'"
|
36
|
+
curl_command << " \\\n -X #{env['REQUEST_METHOD']}" unless ['GET', 'POST'].member?(env['REQUEST_METHOD'])
|
37
|
+
headers.each_pair do |header, value|
|
38
|
+
curl_command << " \\\n -H '#{header}: #{value}'"
|
39
|
+
end
|
40
|
+
curl_command << " \\\n --data '#{body}'" if body && !body.empty?
|
41
|
+
|
42
|
+
curl_command
|
43
|
+
end
|
44
|
+
end
|
data/rack_curler.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack_curler/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack_curler"
|
8
|
+
spec.version = RackCurler::VERSION
|
9
|
+
spec.authors = ["Nathan Speed"]
|
10
|
+
spec.email = ["speedarius@gmail.com"]
|
11
|
+
spec.description = %q{Generate curl commands that approximate rack requests.}
|
12
|
+
spec.summary = %q{Given a rack env, generate a prettified curl command that approximates the request, including headers and request body. Suitable for debugging.}
|
13
|
+
spec.homepage = "https://github.com/speedarius/rack_curler"
|
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 "rack"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
26
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'rack_curler'
|
2
|
+
require 'rack/mock'
|
3
|
+
|
4
|
+
describe RackCurler do
|
5
|
+
it "has a version" do
|
6
|
+
RackCurler::VERSION.should_not be_nil
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "to_curl" do
|
10
|
+
before(:each) do
|
11
|
+
@get_env = lambda do |options={}|
|
12
|
+
env = Rack::MockRequest.env_for('http://foo.example.com', options)
|
13
|
+
env['HTTP_VERSION'] = '1.2.3.4'
|
14
|
+
env['HTTP_HOST'] = 'foo.example.com'
|
15
|
+
env['HTTP_CONNECTION'] = 'close'
|
16
|
+
env['HTTP_ACCEPT_ENCODING'] = 'deflate, gzip'
|
17
|
+
env['HTTP_DATE'] = '2013-11-06 16:52:05 -0800'
|
18
|
+
env['HTTP_ACCEPT'] = '*/*'
|
19
|
+
env['HTTP_SOME_OTHER_HEADER'] = 'header value 123'
|
20
|
+
env
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
shared_examples_for "a request for http://foo.example.com" do
|
25
|
+
it "is a curl command" do
|
26
|
+
@output.should match /^curl /
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has a url argument of http://foo.example.com" do
|
30
|
+
@output.should match /^curl 'http:\/\/foo\.example\.com\/?'/
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does not specify a Version header (curl should choose this)" do
|
34
|
+
@output.should_not match /-H 'Version:/
|
35
|
+
end
|
36
|
+
|
37
|
+
it "does not specify a Host header (curl does this for you)" do
|
38
|
+
@output.should_not match /-H 'Host:/
|
39
|
+
end
|
40
|
+
|
41
|
+
it "does not specify a Connection header (curl does this for you)" do
|
42
|
+
@output.should_not match /-H 'Connection:/
|
43
|
+
end
|
44
|
+
|
45
|
+
it "does not specify an Accept-Encoding header (for debugging, you don't want an encoded response)" do
|
46
|
+
@output.should_not match /-H 'Accept-Encoding:/
|
47
|
+
end
|
48
|
+
|
49
|
+
it "does not specify a Date header (curl will do this for you)" do
|
50
|
+
@output.should_not match /-H 'Date:/
|
51
|
+
end
|
52
|
+
|
53
|
+
it "does not have a redundant Accept header (curl will use */* by default)" do
|
54
|
+
@output.should_not match /-H 'Accept:/
|
55
|
+
end
|
56
|
+
|
57
|
+
it "does include any other header" do
|
58
|
+
@output.should match /-H 'Some-Other-Header: header value 123'/
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'with non-default Accept' do
|
62
|
+
before(:each) do
|
63
|
+
@env['HTTP_ACCEPT'] = 'something specific'
|
64
|
+
@output = RackCurler.to_curl(@env)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "does include the Accept header" do
|
68
|
+
@output.should match /-H 'Accept: something specific'/
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
shared_examples_for "a request for http://foo.example.com without a body" do
|
74
|
+
it "does not have a --data argument" do
|
75
|
+
@output.should_not match /--data/
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
shared_examples_for "a request for http://foo.example.com with a body" do
|
80
|
+
it "does not specify a Content-Length header (curl will set this for you)" do
|
81
|
+
@output.should_not match /-H 'Content-Length:/
|
82
|
+
end
|
83
|
+
|
84
|
+
it "does not specify a redundant Content-Type header (curl will assume application/x-www-form-urlencoded)" do
|
85
|
+
@output.should_not match /-H 'Content-Type:/
|
86
|
+
end
|
87
|
+
|
88
|
+
it "includes the body in a --data argument" do
|
89
|
+
@output.should match /--data 'some body'/
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'with non-default Content-Type' do
|
93
|
+
before(:each) do
|
94
|
+
@env['CONTENT_TYPE'] = 'hello'
|
95
|
+
@output = RackCurler.to_curl(@env)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "does specify a Content-Type header" do
|
99
|
+
@output.should match /-H 'Content-Type: hello'/
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'for a GET to http://foo.example.com' do
|
105
|
+
before(:each) do
|
106
|
+
@env = @get_env.call :method => 'GET'
|
107
|
+
@output = RackCurler.to_curl(@env)
|
108
|
+
end
|
109
|
+
|
110
|
+
it_behaves_like "a request for http://foo.example.com"
|
111
|
+
it_behaves_like "a request for http://foo.example.com without a body"
|
112
|
+
|
113
|
+
it "does not have a -X argument (curl will assume it is a GET)" do
|
114
|
+
@output.should_not match /-X GET/
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'for a DELETE to http://foo.example.com' do
|
119
|
+
before(:each) do
|
120
|
+
@env = @get_env.call :method => 'DELETE'
|
121
|
+
@output = RackCurler.to_curl(@env)
|
122
|
+
end
|
123
|
+
|
124
|
+
it_behaves_like "a request for http://foo.example.com"
|
125
|
+
it_behaves_like "a request for http://foo.example.com without a body"
|
126
|
+
|
127
|
+
it "specifies -X DELETE" do
|
128
|
+
@output.should match /-X DELETE/
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe 'for a PUT to http://foo.example.com' do
|
133
|
+
before(:each) do
|
134
|
+
@env = @get_env.call :method => 'PUT', :input => 'some body'
|
135
|
+
@output = RackCurler.to_curl(@env)
|
136
|
+
end
|
137
|
+
|
138
|
+
it_behaves_like "a request for http://foo.example.com"
|
139
|
+
it_behaves_like "a request for http://foo.example.com with a body"
|
140
|
+
|
141
|
+
it "specifies -X PUT" do
|
142
|
+
@output.should match /-X PUT/
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe 'for a POST to http://foo.example.com' do
|
147
|
+
before(:each) do
|
148
|
+
@env = @get_env.call :method => 'POST', :input => 'some body'
|
149
|
+
@output = RackCurler.to_curl(@env)
|
150
|
+
end
|
151
|
+
|
152
|
+
it_behaves_like "a request for http://foo.example.com"
|
153
|
+
it_behaves_like "a request for http://foo.example.com with a body"
|
154
|
+
|
155
|
+
it "does not specify -X POST (curl will assume it is a POST)" do
|
156
|
+
@output.should_not match /-X POST/
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack_curler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathan Speed
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.6'
|
69
|
+
description: Generate curl commands that approximate rack requests.
|
70
|
+
email:
|
71
|
+
- speedarius@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .ruby-gemset
|
78
|
+
- .ruby-version
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/rack_curler.rb
|
84
|
+
- lib/rack_curler/version.rb
|
85
|
+
- rack_curler.gemspec
|
86
|
+
- spec/rack_curler_spec.rb
|
87
|
+
homepage: https://github.com/speedarius/rack_curler
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.1.10
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Given a rack env, generate a prettified curl command that approximates the
|
111
|
+
request, including headers and request body. Suitable for debugging.
|
112
|
+
test_files:
|
113
|
+
- spec/rack_curler_spec.rb
|