http 0.7.4 → 0.8.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.rubocop.yml +5 -2
- data/CHANGES.md +24 -7
- data/CONTRIBUTING.md +25 -0
- data/Gemfile +24 -22
- data/Guardfile +2 -2
- data/README.md +34 -4
- data/Rakefile +7 -7
- data/examples/parallel_requests_with_celluloid.rb +2 -2
- data/http.gemspec +12 -12
- data/lib/http.rb +11 -10
- data/lib/http/cache.rb +146 -0
- data/lib/http/cache/headers.rb +100 -0
- data/lib/http/cache/null_cache.rb +13 -0
- data/lib/http/chainable.rb +14 -3
- data/lib/http/client.rb +64 -80
- data/lib/http/connection.rb +139 -0
- data/lib/http/content_type.rb +2 -2
- data/lib/http/errors.rb +7 -1
- data/lib/http/headers.rb +21 -8
- data/lib/http/headers/mixin.rb +1 -1
- data/lib/http/mime_type.rb +2 -2
- data/lib/http/mime_type/adapter.rb +2 -2
- data/lib/http/mime_type/json.rb +4 -4
- data/lib/http/options.rb +65 -74
- data/lib/http/redirector.rb +3 -3
- data/lib/http/request.rb +20 -13
- data/lib/http/request/caching.rb +95 -0
- data/lib/http/request/writer.rb +5 -5
- data/lib/http/response.rb +15 -9
- data/lib/http/response/body.rb +21 -8
- data/lib/http/response/caching.rb +142 -0
- data/lib/http/response/io_body.rb +63 -0
- data/lib/http/response/parser.rb +1 -1
- data/lib/http/response/status.rb +4 -12
- data/lib/http/response/status/reasons.rb +53 -53
- data/lib/http/response/string_body.rb +53 -0
- data/lib/http/version.rb +1 -1
- data/spec/lib/http/cache/headers_spec.rb +77 -0
- data/spec/lib/http/cache_spec.rb +182 -0
- data/spec/lib/http/client_spec.rb +123 -95
- data/spec/lib/http/content_type_spec.rb +25 -25
- data/spec/lib/http/headers/mixin_spec.rb +8 -8
- data/spec/lib/http/headers_spec.rb +213 -173
- data/spec/lib/http/options/body_spec.rb +5 -5
- data/spec/lib/http/options/form_spec.rb +3 -3
- data/spec/lib/http/options/headers_spec.rb +7 -7
- data/spec/lib/http/options/json_spec.rb +3 -3
- data/spec/lib/http/options/merge_spec.rb +26 -22
- data/spec/lib/http/options/new_spec.rb +10 -10
- data/spec/lib/http/options/proxy_spec.rb +8 -8
- data/spec/lib/http/options_spec.rb +2 -2
- data/spec/lib/http/redirector_spec.rb +32 -32
- data/spec/lib/http/request/caching_spec.rb +133 -0
- data/spec/lib/http/request/writer_spec.rb +26 -26
- data/spec/lib/http/request_spec.rb +63 -58
- data/spec/lib/http/response/body_spec.rb +13 -13
- data/spec/lib/http/response/caching_spec.rb +201 -0
- data/spec/lib/http/response/io_body_spec.rb +35 -0
- data/spec/lib/http/response/status_spec.rb +25 -25
- data/spec/lib/http/response/string_body_spec.rb +35 -0
- data/spec/lib/http/response_spec.rb +64 -45
- data/spec/lib/http_spec.rb +103 -76
- data/spec/spec_helper.rb +10 -12
- data/spec/support/connection_reuse_shared.rb +100 -0
- data/spec/support/create_certs.rb +12 -12
- data/spec/support/dummy_server.rb +11 -11
- data/spec/support/dummy_server/servlet.rb +43 -31
- data/spec/support/proxy_server.rb +31 -25
- metadata +57 -8
- data/spec/support/example_server.rb +0 -30
- data/spec/support/example_server/servlet.rb +0 -102
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-03-
|
13
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: http_parser.rb
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- ".travis.yml"
|
70
70
|
- ".yardopts"
|
71
71
|
- CHANGES.md
|
72
|
+
- CONTRIBUTING.md
|
72
73
|
- Gemfile
|
73
74
|
- Guardfile
|
74
75
|
- LICENSE.txt
|
@@ -77,8 +78,12 @@ files:
|
|
77
78
|
- examples/parallel_requests_with_celluloid.rb
|
78
79
|
- http.gemspec
|
79
80
|
- lib/http.rb
|
81
|
+
- lib/http/cache.rb
|
82
|
+
- lib/http/cache/headers.rb
|
83
|
+
- lib/http/cache/null_cache.rb
|
80
84
|
- lib/http/chainable.rb
|
81
85
|
- lib/http/client.rb
|
86
|
+
- lib/http/connection.rb
|
82
87
|
- lib/http/content_type.rb
|
83
88
|
- lib/http/errors.rb
|
84
89
|
- lib/http/headers.rb
|
@@ -89,14 +94,20 @@ files:
|
|
89
94
|
- lib/http/options.rb
|
90
95
|
- lib/http/redirector.rb
|
91
96
|
- lib/http/request.rb
|
97
|
+
- lib/http/request/caching.rb
|
92
98
|
- lib/http/request/writer.rb
|
93
99
|
- lib/http/response.rb
|
94
100
|
- lib/http/response/body.rb
|
101
|
+
- lib/http/response/caching.rb
|
102
|
+
- lib/http/response/io_body.rb
|
95
103
|
- lib/http/response/parser.rb
|
96
104
|
- lib/http/response/status.rb
|
97
105
|
- lib/http/response/status/reasons.rb
|
106
|
+
- lib/http/response/string_body.rb
|
98
107
|
- lib/http/version.rb
|
99
108
|
- logo.png
|
109
|
+
- spec/lib/http/cache/headers_spec.rb
|
110
|
+
- spec/lib/http/cache_spec.rb
|
100
111
|
- spec/lib/http/client_spec.rb
|
101
112
|
- spec/lib/http/content_type_spec.rb
|
102
113
|
- spec/lib/http/headers/mixin_spec.rb
|
@@ -110,20 +121,23 @@ files:
|
|
110
121
|
- spec/lib/http/options/proxy_spec.rb
|
111
122
|
- spec/lib/http/options_spec.rb
|
112
123
|
- spec/lib/http/redirector_spec.rb
|
124
|
+
- spec/lib/http/request/caching_spec.rb
|
113
125
|
- spec/lib/http/request/writer_spec.rb
|
114
126
|
- spec/lib/http/request_spec.rb
|
115
127
|
- spec/lib/http/response/body_spec.rb
|
128
|
+
- spec/lib/http/response/caching_spec.rb
|
129
|
+
- spec/lib/http/response/io_body_spec.rb
|
116
130
|
- spec/lib/http/response/status_spec.rb
|
131
|
+
- spec/lib/http/response/string_body_spec.rb
|
117
132
|
- spec/lib/http/response_spec.rb
|
118
133
|
- spec/lib/http_spec.rb
|
119
134
|
- spec/spec_helper.rb
|
120
135
|
- spec/support/black_hole.rb
|
121
136
|
- spec/support/capture_warning.rb
|
137
|
+
- spec/support/connection_reuse_shared.rb
|
122
138
|
- spec/support/create_certs.rb
|
123
139
|
- spec/support/dummy_server.rb
|
124
140
|
- spec/support/dummy_server/servlet.rb
|
125
|
-
- spec/support/example_server.rb
|
126
|
-
- spec/support/example_server/servlet.rb
|
127
141
|
- spec/support/proxy_server.rb
|
128
142
|
- spec/support/servers/config.rb
|
129
143
|
- spec/support/servers/runner.rb
|
@@ -142,14 +156,49 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
156
|
version: '0'
|
143
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
158
|
requirements:
|
145
|
-
- - "
|
159
|
+
- - ">"
|
146
160
|
- !ruby/object:Gem::Version
|
147
|
-
version:
|
161
|
+
version: 1.3.1
|
148
162
|
requirements: []
|
149
163
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.4.6
|
151
165
|
signing_key:
|
152
166
|
specification_version: 4
|
153
167
|
summary: HTTP should be easy
|
154
|
-
test_files:
|
168
|
+
test_files:
|
169
|
+
- spec/lib/http/cache/headers_spec.rb
|
170
|
+
- spec/lib/http/cache_spec.rb
|
171
|
+
- spec/lib/http/client_spec.rb
|
172
|
+
- spec/lib/http/content_type_spec.rb
|
173
|
+
- spec/lib/http/headers/mixin_spec.rb
|
174
|
+
- spec/lib/http/headers_spec.rb
|
175
|
+
- spec/lib/http/options/body_spec.rb
|
176
|
+
- spec/lib/http/options/form_spec.rb
|
177
|
+
- spec/lib/http/options/headers_spec.rb
|
178
|
+
- spec/lib/http/options/json_spec.rb
|
179
|
+
- spec/lib/http/options/merge_spec.rb
|
180
|
+
- spec/lib/http/options/new_spec.rb
|
181
|
+
- spec/lib/http/options/proxy_spec.rb
|
182
|
+
- spec/lib/http/options_spec.rb
|
183
|
+
- spec/lib/http/redirector_spec.rb
|
184
|
+
- spec/lib/http/request/caching_spec.rb
|
185
|
+
- spec/lib/http/request/writer_spec.rb
|
186
|
+
- spec/lib/http/request_spec.rb
|
187
|
+
- spec/lib/http/response/body_spec.rb
|
188
|
+
- spec/lib/http/response/caching_spec.rb
|
189
|
+
- spec/lib/http/response/io_body_spec.rb
|
190
|
+
- spec/lib/http/response/status_spec.rb
|
191
|
+
- spec/lib/http/response/string_body_spec.rb
|
192
|
+
- spec/lib/http/response_spec.rb
|
193
|
+
- spec/lib/http_spec.rb
|
194
|
+
- spec/spec_helper.rb
|
195
|
+
- spec/support/black_hole.rb
|
196
|
+
- spec/support/capture_warning.rb
|
197
|
+
- spec/support/connection_reuse_shared.rb
|
198
|
+
- spec/support/create_certs.rb
|
199
|
+
- spec/support/dummy_server.rb
|
200
|
+
- spec/support/dummy_server/servlet.rb
|
201
|
+
- spec/support/proxy_server.rb
|
202
|
+
- spec/support/servers/config.rb
|
203
|
+
- spec/support/servers/runner.rb
|
155
204
|
has_rdoc:
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'webrick'
|
2
|
-
require 'singleton'
|
3
|
-
require 'forwardable'
|
4
|
-
|
5
|
-
require 'support/example_server/servlet'
|
6
|
-
|
7
|
-
class ExampleServer
|
8
|
-
extend Forwardable
|
9
|
-
|
10
|
-
include Singleton
|
11
|
-
|
12
|
-
PORT = 65_432
|
13
|
-
ADDR = "127.0.0.1:#{PORT}"
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@server = WEBrick::HTTPServer.new :Port => PORT, :AccessLog => []
|
17
|
-
@server.mount '/', Servlet
|
18
|
-
end
|
19
|
-
|
20
|
-
delegate [:start, :shutdown] => :@server
|
21
|
-
end
|
22
|
-
|
23
|
-
t = Thread.new { ExampleServer.instance.start }
|
24
|
-
|
25
|
-
trap('INT') do
|
26
|
-
ExampleServer.instance.shutdown
|
27
|
-
exit
|
28
|
-
end
|
29
|
-
|
30
|
-
Thread.pass while t.status && t.status != 'sleep'
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'webrick'
|
2
|
-
|
3
|
-
class ExampleServer
|
4
|
-
class Servlet < WEBrick::HTTPServlet::AbstractServlet
|
5
|
-
def not_found(_req, res)
|
6
|
-
res.status = 404
|
7
|
-
res.body = 'Not Found'
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.handlers
|
11
|
-
@handlers ||= {}
|
12
|
-
end
|
13
|
-
|
14
|
-
%w(get post head).each do |method|
|
15
|
-
class_eval <<-RUBY, __FILE__, __LINE__
|
16
|
-
def self.#{method}(path, &block)
|
17
|
-
handlers["#{method}:\#{path}"] = block
|
18
|
-
end
|
19
|
-
|
20
|
-
def do_#{method.upcase}(req, res)
|
21
|
-
handler = self.class.handlers["#{method}:\#{req.path}"]
|
22
|
-
return instance_exec(req, res, &handler) if handler
|
23
|
-
not_found
|
24
|
-
end
|
25
|
-
RUBY
|
26
|
-
end
|
27
|
-
|
28
|
-
get '/' do |req, res|
|
29
|
-
res.status = 200
|
30
|
-
|
31
|
-
case req['Accept']
|
32
|
-
when 'application/json'
|
33
|
-
res['Content-Type'] = 'application/json'
|
34
|
-
res.body = '{"json": true}'
|
35
|
-
else
|
36
|
-
res['Content-Type'] = 'text/html'
|
37
|
-
res.body = '<!doctype html>'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
get '/params' do |req, res|
|
42
|
-
next not_found unless 'foo=bar' == req.query_string
|
43
|
-
|
44
|
-
res.status = 200
|
45
|
-
res.body = 'Params!'
|
46
|
-
end
|
47
|
-
|
48
|
-
get '/multiple-params' do |req, res|
|
49
|
-
params = CGI.parse req.query_string
|
50
|
-
|
51
|
-
next not_found unless {'foo' => ['bar'], 'baz' => ['quux']} == params
|
52
|
-
|
53
|
-
res.status = 200
|
54
|
-
res.body = 'More Params!'
|
55
|
-
end
|
56
|
-
|
57
|
-
get '/proxy' do |_req, res|
|
58
|
-
res.status = 200
|
59
|
-
res.body = 'Proxy!'
|
60
|
-
end
|
61
|
-
|
62
|
-
get '/not-found' do |_req, res|
|
63
|
-
res.status = 404
|
64
|
-
res.body = 'not found'
|
65
|
-
end
|
66
|
-
|
67
|
-
get '/redirect-301' do |_req, res|
|
68
|
-
res.status = 301
|
69
|
-
res['Location'] = "http://#{ExampleServer::ADDR}/"
|
70
|
-
end
|
71
|
-
|
72
|
-
get '/redirect-302' do |_req, res|
|
73
|
-
res.status = 302
|
74
|
-
res['Location'] = "http://#{ExampleServer::ADDR}/"
|
75
|
-
end
|
76
|
-
|
77
|
-
post '/form' do |req, res|
|
78
|
-
if 'testing-form' == req.query['example']
|
79
|
-
res.status = 200
|
80
|
-
res.body = 'passed :)'
|
81
|
-
else
|
82
|
-
res.status = 400
|
83
|
-
res.body = 'invalid! >:E'
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
post '/body' do |req, res|
|
88
|
-
if 'testing-body' == req.body
|
89
|
-
res.status = 200
|
90
|
-
res.body = 'passed :)'
|
91
|
-
else
|
92
|
-
res.status = 400
|
93
|
-
res.body = 'invalid! >:E'
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
head '/' do |_req, res|
|
98
|
-
res.status = 200
|
99
|
-
res['Content-Type'] = 'text/html'
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|