http 1.0.0.pre3 → 1.0.0.pre4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e1927443d777f84c1531531c9dec4e0b6eba9ff
4
- data.tar.gz: 4ac6e616a529191f56f7af34dd71e3fb93667155
3
+ metadata.gz: 9b68e3604886c916e6e4f1fd3607704c781d5895
4
+ data.tar.gz: e7ec1fece7b666199c2f5dab353530c0669a512a
5
5
  SHA512:
6
- metadata.gz: 2f9b035441245faf2b3124cf4c2562b705ac74d1522f75216f31d7dcff91779acae067845127b0cca63ccf0159567ae11ed94408425cf4626d072178ed09d4a1
7
- data.tar.gz: 44745a975c4fe5595857ed2214cdc9ec1d7caf0bb5c146270a2a9630574955d2ad33b63a600d8c9d0c2898facb59bd8cfc9f9685c972a66e8c4c23532a4659c1
6
+ metadata.gz: 642f976768af7e7bbebf7e8a1639c539bd168001b0dd7b1bf0369fe310a0ba94a15a377a14ae7d9725c08c4d45af1e8d2fbaecb1fa72591718e740a455e47a3f
7
+ data.tar.gz: 299d773b6b6ca345116fa3c2d2f87d8e55fe2203af198fb7ab4af1c09d8c550a2cac88ba4fcc3ec59a86e32969cec41dfe91b7ae2383ae73ff8dbad0fe51b616
data/CHANGES.md CHANGED
@@ -1,4 +1,4 @@
1
- ## 1.0.0.pre2 (2015-12-18)
1
+ ## 1.0.0.pre4 (2015-12-18)
2
2
 
3
3
  * [#265](https://github.com/httprb/http/pull/265/):
4
4
  Remove deprecations ([@tarcieri]):
@@ -34,6 +34,11 @@
34
34
  Use Encoding::BINARY as the default encoding for HTTP::Response::Body.
35
35
  ([@tarcieri])
36
36
 
37
+ * [#278](https://github.com/httprb/http/pull/278)
38
+ Use an options hash for HTTP::Request's initializer API.
39
+ ([@ixti])
40
+
41
+
37
42
  ## 0.9.8 (2015-09-29)
38
43
 
39
44
  * [#260](https://github.com/httprb/http/pull/258):
@@ -435,3 +440,4 @@ end
435
440
  [@krainboltgreene]: https://github.com/krainboltgreene
436
441
  [@hundredwatt]: https://github.com/hundredwatt
437
442
  [@jwinter]: https://github.com/jwinter
443
+ [@nerdrew]: https://github.com/nerdrew
@@ -32,13 +32,19 @@ module HTTP
32
32
  body = make_request_body(opts, headers)
33
33
  proxy = opts.proxy
34
34
 
35
- req = HTTP::Request.new(verb, uri, headers, proxy, body)
36
- res = perform req, opts
35
+ req = HTTP::Request.new(
36
+ :verb => verb,
37
+ :uri => uri,
38
+ :headers => headers,
39
+ :proxy => proxy,
40
+ :body => body
41
+ )
37
42
 
43
+ res = perform(req, opts)
38
44
  return res unless opts.follow
39
45
 
40
- Redirector.new(opts.follow).perform req, res do |request|
41
- perform request, opts
46
+ Redirector.new(opts.follow).perform(req, res) do |request|
47
+ perform(request, opts)
42
48
  end
43
49
  end
44
50
 
@@ -61,12 +67,12 @@ module HTTP
61
67
  end
62
68
 
63
69
  res = Response.new(
64
- :status => @connection.status_code,
65
- :version => @connection.http_version,
66
- :headers => @connection.headers,
70
+ :status => @connection.status_code,
71
+ :version => @connection.http_version,
72
+ :headers => @connection.headers,
67
73
  :connection => @connection,
68
- :encoding => options.encoding,
69
- :uri => req.uri
74
+ :encoding => options.encoding,
75
+ :uri => req.uri
70
76
  )
71
77
 
72
78
  @connection.finish_response if req.verb == :head
@@ -63,20 +63,24 @@ module HTTP
63
63
  attr_reader :uri
64
64
  attr_reader :proxy, :body, :version
65
65
 
66
- # :nodoc:
67
- def initialize(verb, uri, headers = {}, proxy = {}, body = nil, version = "1.1") # rubocop:disable ParameterLists
68
- @verb = verb.to_s.downcase.to_sym
69
- @uri = normalize_uri uri
70
- @scheme = @uri.scheme && @uri.scheme.to_s.downcase.to_sym
66
+ # @option opts [String] :version
67
+ # @option opts [#to_s] :verb HTTP request method
68
+ # @option opts [HTTP::URI, #to_s] :uri
69
+ # @option opts [Hash] :headers
70
+ # @option opts [Hash] :proxy
71
+ # @option opts [String] :body
72
+ def initialize(opts)
73
+ @verb = opts.fetch(:verb).to_s.downcase.to_sym
74
+ @uri = normalize_uri(opts.fetch :uri)
75
+ @scheme = @uri.scheme.to_s.downcase.to_sym if @uri.scheme
71
76
 
72
77
  fail(UnsupportedMethodError, "unknown method: #{verb}") unless METHODS.include?(@verb)
73
78
  fail(UnsupportedSchemeError, "unknown scheme: #{scheme}") unless SCHEMES.include?(@scheme)
74
79
 
75
- @proxy = proxy
76
- @body = body
77
- @version = version
78
-
79
- @headers = HTTP::Headers.coerce(headers || {})
80
+ @proxy = opts[:proxy] || {}
81
+ @body = opts[:body]
82
+ @version = opts[:version] || "1.1"
83
+ @headers = HTTP::Headers.coerce(opts[:headers] || {})
80
84
 
81
85
  @headers[Headers::HOST] ||= default_host_header_value
82
86
  @headers[Headers::USER_AGENT] ||= USER_AGENT
@@ -84,7 +88,15 @@ module HTTP
84
88
 
85
89
  # Returns new Request with updated uri
86
90
  def redirect(uri, verb = @verb)
87
- req = self.class.new(verb, @uri.join(uri), headers, proxy, body, version)
91
+ req = self.class.new(
92
+ :verb => verb,
93
+ :uri => @uri.join(uri),
94
+ :headers => headers,
95
+ :proxy => proxy,
96
+ :body => body,
97
+ :version => version
98
+ )
99
+
88
100
  req[Headers::HOST] = req.uri.host
89
101
  req
90
102
  end
@@ -34,13 +34,15 @@ module HTTP
34
34
  # @option opts [String] :uri
35
35
  def initialize(opts)
36
36
  @version = opts.fetch(:version)
37
- @uri = opts.include?(:uri) && HTTP::URI.parse(opts.fetch(:uri))
38
- @status = HTTP::Response::Status.new opts.fetch(:status)
39
- @headers = HTTP::Headers.coerce(opts.fetch(:headers, {}))
37
+ @uri = HTTP::URI.parse(opts.fetch :uri) if opts.include? :uri
38
+ @status = HTTP::Response::Status.new(opts.fetch :status)
39
+ @headers = HTTP::Headers.coerce(opts[:headers] || {})
40
40
 
41
41
  if opts.include?(:connection)
42
- encoding = opts[:encoding] || charset || Encoding::BINARY
43
- @body = Response::Body.new(opts.fetch(:connection), encoding)
42
+ connection = opts.fetch(:connection)
43
+ encoding = opts[:encoding] || charset || Encoding::BINARY
44
+
45
+ @body = Response::Body.new(connection, encoding)
44
46
  else
45
47
  @body = opts.fetch(:body)
46
48
  end
@@ -1,3 +1,3 @@
1
1
  module HTTP
2
- VERSION = "1.0.0.pre3".freeze
2
+ VERSION = "1.0.0.pre4".freeze
3
3
  end
@@ -27,17 +27,19 @@ RSpec.describe HTTP::Client do
27
27
 
28
28
  def redirect_response(location, status = 302)
29
29
  HTTP::Response.new(
30
- :status => status,
30
+ :status => status,
31
31
  :version => "1.1",
32
32
  :headers => {"Location" => location},
33
- :body => "")
33
+ :body => ""
34
+ )
34
35
  end
35
36
 
36
37
  def simple_response(body, status = 200)
37
38
  HTTP::Response.new(
38
- :status => status,
39
+ :status => status,
39
40
  :version => "1.1",
40
- :body => body)
41
+ :body => body
42
+ )
41
43
  end
42
44
 
43
45
  describe "following redirects" do
@@ -107,48 +109,48 @@ RSpec.describe HTTP::Client do
107
109
  before { allow(client).to receive :perform }
108
110
 
109
111
  it "accepts params within the provided URL" do
110
- expect(HTTP::Request).to receive(:new) do |_, uri|
111
- expect(CGI.parse uri.query).to eq("foo" => %w(bar))
112
+ expect(HTTP::Request).to receive(:new) do |opts|
113
+ expect(CGI.parse opts[:uri].query).to eq("foo" => %w(bar))
112
114
  end
113
115
 
114
116
  client.get("http://example.com/?foo=bar")
115
117
  end
116
118
 
117
119
  it "combines GET params from the URI with the passed in params" do
118
- expect(HTTP::Request).to receive(:new) do |_, uri|
119
- expect(CGI.parse uri.query).to eq("foo" => %w(bar), "baz" => %w(quux))
120
+ expect(HTTP::Request).to receive(:new) do |opts|
121
+ expect(CGI.parse opts[:uri].query).to eq("foo" => %w(bar), "baz" => %w(quux))
120
122
  end
121
123
 
122
124
  client.get("http://example.com/?foo=bar", :params => {:baz => "quux"})
123
125
  end
124
126
 
125
127
  it "merges duplicate values" do
126
- expect(HTTP::Request).to receive(:new) do |_, uri|
127
- expect(uri.query).to match(/^(a=1&a=2|a=2&a=1)$/)
128
+ expect(HTTP::Request).to receive(:new) do |opts|
129
+ expect(opts[:uri].query).to match(/^(a=1&a=2|a=2&a=1)$/)
128
130
  end
129
131
 
130
132
  client.get("http://example.com/?a=1", :params => {:a => 2})
131
133
  end
132
134
 
133
135
  it "does not modifies query part if no params were given" do
134
- expect(HTTP::Request).to receive(:new) do |_, uri|
135
- expect(uri.query).to eq "deadbeef"
136
+ expect(HTTP::Request).to receive(:new) do |opts|
137
+ expect(opts[:uri].query).to eq "deadbeef"
136
138
  end
137
139
 
138
140
  client.get("http://example.com/?deadbeef")
139
141
  end
140
142
 
141
143
  it "does not corrupts index-less arrays" do
142
- expect(HTTP::Request).to receive(:new) do |_, uri|
143
- expect(CGI.parse uri.query).to eq "a[]" => %w(b c), "d" => %w(e)
144
+ expect(HTTP::Request).to receive(:new) do |opts|
145
+ expect(CGI.parse opts[:uri].query).to eq "a[]" => %w(b c), "d" => %w(e)
144
146
  end
145
147
 
146
148
  client.get("http://example.com/?a[]=b&a[]=c", :params => {:d => "e"})
147
149
  end
148
150
 
149
151
  it "properly encodes colons" do
150
- expect(HTTP::Request).to receive(:new) do |_, uri|
151
- expect(uri.query).to eq "t=1970-01-01T00%3A00%3A00Z"
152
+ expect(HTTP::Request).to receive(:new) do |opts|
153
+ expect(opts[:uri].query).to eq "t=1970-01-01T00%3A00%3A00Z"
152
154
  end
153
155
 
154
156
  client.get("http://example.com/", :params => {:t => "1970-01-01T00:00:00Z"})
@@ -160,8 +162,8 @@ RSpec.describe HTTP::Client do
160
162
  client = HTTP::Client.new
161
163
  allow(client).to receive(:perform)
162
164
 
163
- expect(HTTP::Request).to receive(:new) do |*args|
164
- expect(args.last).to eq('{"foo":"bar"}')
165
+ expect(HTTP::Request).to receive(:new) do |opts|
166
+ expect(opts[:body]).to eq '{"foo":"bar"}'
165
167
  end
166
168
 
167
169
  client.get("http://example.com/", :json => {:foo => :bar})
@@ -1,10 +1,10 @@
1
1
  RSpec.describe HTTP::Redirector do
2
2
  def simple_response(status, body = "", headers = {})
3
3
  HTTP::Response.new(
4
- :status => status,
4
+ :status => status,
5
5
  :version => "1.1",
6
6
  :headers => headers,
7
- :body => body
7
+ :body => body
8
8
  )
9
9
  end
10
10
 
@@ -35,7 +35,7 @@ RSpec.describe HTTP::Redirector do
35
35
  let(:redirector) { described_class.new options }
36
36
 
37
37
  it "fails with TooManyRedirectsError if max hops reached" do
38
- req = HTTP::Request.new :head, "http://example.com"
38
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
39
39
  res = proc { |prev_req| redirect_response(301, "#{prev_req.uri}/1") }
40
40
 
41
41
  expect { redirector.perform(req, res.call(req), &res) }.
@@ -43,7 +43,7 @@ RSpec.describe HTTP::Redirector do
43
43
  end
44
44
 
45
45
  it "fails with EndlessRedirectError if endless loop detected" do
46
- req = HTTP::Request.new :head, "http://example.com"
46
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
47
47
  res = redirect_response(301, req.uri)
48
48
 
49
49
  expect { redirector.perform(req, res) { res } }.
@@ -51,7 +51,7 @@ RSpec.describe HTTP::Redirector do
51
51
  end
52
52
 
53
53
  it "fails with StateError if there were no Location header" do
54
- req = HTTP::Request.new :head, "http://example.com"
54
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
55
55
  res = simple_response(301)
56
56
 
57
57
  expect { |b| redirector.perform(req, res, &b) }.
@@ -59,7 +59,7 @@ RSpec.describe HTTP::Redirector do
59
59
  end
60
60
 
61
61
  it "returns first non-redirect response" do
62
- req = HTTP::Request.new :head, "http://example.com"
62
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
63
63
  hops = [
64
64
  redirect_response(301, "http://example.com/1"),
65
65
  redirect_response(301, "http://example.com/2"),
@@ -78,7 +78,7 @@ RSpec.describe HTTP::Redirector do
78
78
  let(:options) { {:strict => true} }
79
79
 
80
80
  it "it follows with original verb if it's safe" do
81
- req = HTTP::Request.new :head, "http://example.com"
81
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
82
82
  res = redirect_response 300, "http://example.com/1"
83
83
 
84
84
  redirector.perform(req, res) do |prev_req, _|
@@ -88,7 +88,7 @@ RSpec.describe HTTP::Redirector do
88
88
  end
89
89
 
90
90
  it "raises StateError if original request was PUT" do
91
- req = HTTP::Request.new :put, "http://example.com"
91
+ req = HTTP::Request.new :verb => :put, :uri => "http://example.com"
92
92
  res = redirect_response 300, "http://example.com/1"
93
93
 
94
94
  expect { redirector.perform(req, res) { simple_response 200 } }.
@@ -96,7 +96,7 @@ RSpec.describe HTTP::Redirector do
96
96
  end
97
97
 
98
98
  it "raises StateError if original request was POST" do
99
- req = HTTP::Request.new :post, "http://example.com"
99
+ req = HTTP::Request.new :verb => :post, :uri => "http://example.com"
100
100
  res = redirect_response 300, "http://example.com/1"
101
101
 
102
102
  expect { redirector.perform(req, res) { simple_response 200 } }.
@@ -104,7 +104,7 @@ RSpec.describe HTTP::Redirector do
104
104
  end
105
105
 
106
106
  it "raises StateError if original request was DELETE" do
107
- req = HTTP::Request.new :delete, "http://example.com"
107
+ req = HTTP::Request.new :verb => :delete, :uri => "http://example.com"
108
108
  res = redirect_response 300, "http://example.com/1"
109
109
 
110
110
  expect { redirector.perform(req, res) { simple_response 200 } }.
@@ -116,7 +116,7 @@ RSpec.describe HTTP::Redirector do
116
116
  let(:options) { {:strict => false} }
117
117
 
118
118
  it "it follows with original verb if it's safe" do
119
- req = HTTP::Request.new :head, "http://example.com"
119
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
120
120
  res = redirect_response 300, "http://example.com/1"
121
121
 
122
122
  redirector.perform(req, res) do |prev_req, _|
@@ -126,7 +126,7 @@ RSpec.describe HTTP::Redirector do
126
126
  end
127
127
 
128
128
  it "it follows with GET if original request was PUT" do
129
- req = HTTP::Request.new :put, "http://example.com"
129
+ req = HTTP::Request.new :verb => :put, :uri => "http://example.com"
130
130
  res = redirect_response 300, "http://example.com/1"
131
131
 
132
132
  redirector.perform(req, res) do |prev_req, _|
@@ -136,7 +136,7 @@ RSpec.describe HTTP::Redirector do
136
136
  end
137
137
 
138
138
  it "it follows with GET if original request was POST" do
139
- req = HTTP::Request.new :post, "http://example.com"
139
+ req = HTTP::Request.new :verb => :post, :uri => "http://example.com"
140
140
  res = redirect_response 300, "http://example.com/1"
141
141
 
142
142
  redirector.perform(req, res) do |prev_req, _|
@@ -146,7 +146,7 @@ RSpec.describe HTTP::Redirector do
146
146
  end
147
147
 
148
148
  it "it follows with GET if original request was DELETE" do
149
- req = HTTP::Request.new :delete, "http://example.com"
149
+ req = HTTP::Request.new :verb => :delete, :uri => "http://example.com"
150
150
  res = redirect_response 300, "http://example.com/1"
151
151
 
152
152
  redirector.perform(req, res) do |prev_req, _|
@@ -162,7 +162,7 @@ RSpec.describe HTTP::Redirector do
162
162
  let(:options) { {:strict => true} }
163
163
 
164
164
  it "it follows with original verb if it's safe" do
165
- req = HTTP::Request.new :head, "http://example.com"
165
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
166
166
  res = redirect_response 301, "http://example.com/1"
167
167
 
168
168
  redirector.perform(req, res) do |prev_req, _|
@@ -172,7 +172,7 @@ RSpec.describe HTTP::Redirector do
172
172
  end
173
173
 
174
174
  it "raises StateError if original request was PUT" do
175
- req = HTTP::Request.new :put, "http://example.com"
175
+ req = HTTP::Request.new :verb => :put, :uri => "http://example.com"
176
176
  res = redirect_response 301, "http://example.com/1"
177
177
 
178
178
  expect { redirector.perform(req, res) { simple_response 200 } }.
@@ -180,7 +180,7 @@ RSpec.describe HTTP::Redirector do
180
180
  end
181
181
 
182
182
  it "raises StateError if original request was POST" do
183
- req = HTTP::Request.new :post, "http://example.com"
183
+ req = HTTP::Request.new :verb => :post, :uri => "http://example.com"
184
184
  res = redirect_response 301, "http://example.com/1"
185
185
 
186
186
  expect { redirector.perform(req, res) { simple_response 200 } }.
@@ -188,7 +188,7 @@ RSpec.describe HTTP::Redirector do
188
188
  end
189
189
 
190
190
  it "raises StateError if original request was DELETE" do
191
- req = HTTP::Request.new :delete, "http://example.com"
191
+ req = HTTP::Request.new :verb => :delete, :uri => "http://example.com"
192
192
  res = redirect_response 301, "http://example.com/1"
193
193
 
194
194
  expect { redirector.perform(req, res) { simple_response 200 } }.
@@ -200,7 +200,7 @@ RSpec.describe HTTP::Redirector do
200
200
  let(:options) { {:strict => false} }
201
201
 
202
202
  it "it follows with original verb if it's safe" do
203
- req = HTTP::Request.new :head, "http://example.com"
203
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
204
204
  res = redirect_response 301, "http://example.com/1"
205
205
 
206
206
  redirector.perform(req, res) do |prev_req, _|
@@ -210,7 +210,7 @@ RSpec.describe HTTP::Redirector do
210
210
  end
211
211
 
212
212
  it "it follows with GET if original request was PUT" do
213
- req = HTTP::Request.new :put, "http://example.com"
213
+ req = HTTP::Request.new :verb => :put, :uri => "http://example.com"
214
214
  res = redirect_response 301, "http://example.com/1"
215
215
 
216
216
  redirector.perform(req, res) do |prev_req, _|
@@ -220,7 +220,7 @@ RSpec.describe HTTP::Redirector do
220
220
  end
221
221
 
222
222
  it "it follows with GET if original request was POST" do
223
- req = HTTP::Request.new :post, "http://example.com"
223
+ req = HTTP::Request.new :verb => :post, :uri => "http://example.com"
224
224
  res = redirect_response 301, "http://example.com/1"
225
225
 
226
226
  redirector.perform(req, res) do |prev_req, _|
@@ -230,7 +230,7 @@ RSpec.describe HTTP::Redirector do
230
230
  end
231
231
 
232
232
  it "it follows with GET if original request was DELETE" do
233
- req = HTTP::Request.new :delete, "http://example.com"
233
+ req = HTTP::Request.new :verb => :delete, :uri => "http://example.com"
234
234
  res = redirect_response 301, "http://example.com/1"
235
235
 
236
236
  redirector.perform(req, res) do |prev_req, _|
@@ -246,7 +246,7 @@ RSpec.describe HTTP::Redirector do
246
246
  let(:options) { {:strict => true} }
247
247
 
248
248
  it "it follows with original verb if it's safe" do
249
- req = HTTP::Request.new :head, "http://example.com"
249
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
250
250
  res = redirect_response 302, "http://example.com/1"
251
251
 
252
252
  redirector.perform(req, res) do |prev_req, _|
@@ -256,7 +256,7 @@ RSpec.describe HTTP::Redirector do
256
256
  end
257
257
 
258
258
  it "raises StateError if original request was PUT" do
259
- req = HTTP::Request.new :put, "http://example.com"
259
+ req = HTTP::Request.new :verb => :put, :uri => "http://example.com"
260
260
  res = redirect_response 302, "http://example.com/1"
261
261
 
262
262
  expect { redirector.perform(req, res) { simple_response 200 } }.
@@ -264,7 +264,7 @@ RSpec.describe HTTP::Redirector do
264
264
  end
265
265
 
266
266
  it "raises StateError if original request was POST" do
267
- req = HTTP::Request.new :post, "http://example.com"
267
+ req = HTTP::Request.new :verb => :post, :uri => "http://example.com"
268
268
  res = redirect_response 302, "http://example.com/1"
269
269
 
270
270
  expect { redirector.perform(req, res) { simple_response 200 } }.
@@ -272,7 +272,7 @@ RSpec.describe HTTP::Redirector do
272
272
  end
273
273
 
274
274
  it "raises StateError if original request was DELETE" do
275
- req = HTTP::Request.new :delete, "http://example.com"
275
+ req = HTTP::Request.new :verb => :delete, :uri => "http://example.com"
276
276
  res = redirect_response 302, "http://example.com/1"
277
277
 
278
278
  expect { redirector.perform(req, res) { simple_response 200 } }.
@@ -284,7 +284,7 @@ RSpec.describe HTTP::Redirector do
284
284
  let(:options) { {:strict => false} }
285
285
 
286
286
  it "it follows with original verb if it's safe" do
287
- req = HTTP::Request.new :head, "http://example.com"
287
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
288
288
  res = redirect_response 302, "http://example.com/1"
289
289
 
290
290
  redirector.perform(req, res) do |prev_req, _|
@@ -294,7 +294,7 @@ RSpec.describe HTTP::Redirector do
294
294
  end
295
295
 
296
296
  it "it follows with GET if original request was PUT" do
297
- req = HTTP::Request.new :put, "http://example.com"
297
+ req = HTTP::Request.new :verb => :put, :uri => "http://example.com"
298
298
  res = redirect_response 302, "http://example.com/1"
299
299
 
300
300
  redirector.perform(req, res) do |prev_req, _|
@@ -304,7 +304,7 @@ RSpec.describe HTTP::Redirector do
304
304
  end
305
305
 
306
306
  it "it follows with GET if original request was POST" do
307
- req = HTTP::Request.new :post, "http://example.com"
307
+ req = HTTP::Request.new :verb => :post, :uri => "http://example.com"
308
308
  res = redirect_response 302, "http://example.com/1"
309
309
 
310
310
  redirector.perform(req, res) do |prev_req, _|
@@ -314,7 +314,7 @@ RSpec.describe HTTP::Redirector do
314
314
  end
315
315
 
316
316
  it "it follows with GET if original request was DELETE" do
317
- req = HTTP::Request.new :delete, "http://example.com"
317
+ req = HTTP::Request.new :verb => :delete, :uri => "http://example.com"
318
318
  res = redirect_response 302, "http://example.com/1"
319
319
 
320
320
  redirector.perform(req, res) do |prev_req, _|
@@ -327,7 +327,7 @@ RSpec.describe HTTP::Redirector do
327
327
 
328
328
  context "following 303 redirect" do
329
329
  it "follows with HEAD if original request was HEAD" do
330
- req = HTTP::Request.new :head, "http://example.com"
330
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
331
331
  res = redirect_response 303, "http://example.com/1"
332
332
 
333
333
  redirector.perform(req, res) do |prev_req, _|
@@ -337,7 +337,7 @@ RSpec.describe HTTP::Redirector do
337
337
  end
338
338
 
339
339
  it "follows with GET if original request was GET" do
340
- req = HTTP::Request.new :get, "http://example.com"
340
+ req = HTTP::Request.new :verb => :get, :uri => "http://example.com"
341
341
  res = redirect_response 303, "http://example.com/1"
342
342
 
343
343
  redirector.perform(req, res) do |prev_req, _|
@@ -347,7 +347,7 @@ RSpec.describe HTTP::Redirector do
347
347
  end
348
348
 
349
349
  it "follows with GET if original request was neither GET nor HEAD" do
350
- req = HTTP::Request.new :post, "http://example.com"
350
+ req = HTTP::Request.new :verb => :post, :uri => "http://example.com"
351
351
  res = redirect_response 303, "http://example.com/1"
352
352
 
353
353
  redirector.perform(req, res) do |prev_req, _|
@@ -359,7 +359,7 @@ RSpec.describe HTTP::Redirector do
359
359
 
360
360
  context "following 307 redirect" do
361
361
  it "follows with original request's verb" do
362
- req = HTTP::Request.new :post, "http://example.com"
362
+ req = HTTP::Request.new :verb => :post, :uri => "http://example.com"
363
363
  res = redirect_response 307, "http://example.com/1"
364
364
 
365
365
  redirector.perform(req, res) do |prev_req, _|
@@ -371,7 +371,7 @@ RSpec.describe HTTP::Redirector do
371
371
 
372
372
  context "following 308 redirect" do
373
373
  it "follows with original request's verb" do
374
- req = HTTP::Request.new :post, "http://example.com"
374
+ req = HTTP::Request.new :verb => :post, :uri => "http://example.com"
375
375
  res = redirect_response 308, "http://example.com/1"
376
376
 
377
377
  redirector.perform(req, res) do |prev_req, _|
@@ -5,14 +5,21 @@ RSpec.describe HTTP::Request do
5
5
  let(:headers) { {:accept => "text/html"} }
6
6
  let(:request_uri) { "http://example.com/foo?bar=baz" }
7
7
 
8
- subject(:request) { HTTP::Request.new(:get, request_uri, headers, proxy) }
8
+ subject :request do
9
+ HTTP::Request.new(
10
+ :verb => :get,
11
+ :uri => request_uri,
12
+ :headers => headers,
13
+ :proxy => proxy
14
+ )
15
+ end
9
16
 
10
17
  it "includes HTTP::Headers::Mixin" do
11
18
  expect(described_class).to include HTTP::Headers::Mixin
12
19
  end
13
20
 
14
21
  it "requires URI to have scheme part" do
15
- expect { HTTP::Request.new(:get, "example.com/") }.to \
22
+ expect { HTTP::Request.new(:verb => :get, :uri => "example.com/") }.to \
16
23
  raise_error(HTTP::Request::UnsupportedSchemeError)
17
24
  end
18
25
 
@@ -63,7 +70,16 @@ RSpec.describe HTTP::Request do
63
70
  let(:headers) { {:accept => "text/html"} }
64
71
  let(:proxy) { {:proxy_username => "douglas", :proxy_password => "adams"} }
65
72
  let(:body) { "The Ultimate Question" }
66
- let(:request) { HTTP::Request.new(:post, "http://example.com/", headers, proxy, body) }
73
+
74
+ let :request do
75
+ HTTP::Request.new(
76
+ :verb => :post,
77
+ :uri => "http://example.com/",
78
+ :headers => headers,
79
+ :proxy => proxy,
80
+ :body => body
81
+ )
82
+ end
67
83
 
68
84
  subject(:redirected) { request.redirect "http://blog.example.com/" }
69
85
 
@@ -105,8 +121,17 @@ RSpec.describe HTTP::Request do
105
121
  end
106
122
 
107
123
  context "with original URI having non-standard port" do
108
- let(:request) { HTTP::Request.new(:post, "http://example.com:8080/", headers, proxy, body) }
109
- its(:uri) { is_expected.to eq HTTP::URI.parse "http://example.com:8080/blog" }
124
+ let :request do
125
+ HTTP::Request.new(
126
+ :verb => :post,
127
+ :uri => "http://example.com:8080/",
128
+ :headers => headers,
129
+ :proxy => proxy,
130
+ :body => body
131
+ )
132
+ end
133
+
134
+ its(:uri) { is_expected.to eq HTTP::URI.parse "http://example.com:8080/blog" }
110
135
  end
111
136
  end
112
137
 
@@ -124,8 +149,17 @@ RSpec.describe HTTP::Request do
124
149
  end
125
150
 
126
151
  context "with original URI having non-standard port" do
127
- let(:request) { HTTP::Request.new(:post, "http://example.com:8080/", headers, proxy, body) }
128
- its(:uri) { is_expected.to eq HTTP::URI.parse "http://example.com:8080/blog" }
152
+ let :request do
153
+ HTTP::Request.new(
154
+ :verb => :post,
155
+ :uri => "http://example.com:8080/",
156
+ :headers => headers,
157
+ :proxy => proxy,
158
+ :body => body
159
+ )
160
+ end
161
+
162
+ its(:uri) { is_expected.to eq HTTP::URI.parse "http://example.com:8080/blog" }
129
163
  end
130
164
  end
131
165
 
@@ -5,11 +5,11 @@ RSpec.describe HTTP::Response do
5
5
 
6
6
  subject(:response) do
7
7
  HTTP::Response.new(
8
- :status => 200,
8
+ :status => 200,
9
9
  :version => "1.1",
10
10
  :headers => headers,
11
- :body => body,
12
- :uri => uri
11
+ :body => body,
12
+ :uri => uri
13
13
  )
14
14
  end
15
15
 
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: 1.0.0.pre3
4
+ version: 1.0.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-12-18 00:00:00.000000000 Z
14
+ date: 2015-12-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: http_parser.rb
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  version: 1.3.1
184
184
  requirements: []
185
185
  rubyforge_project:
186
- rubygems_version: 2.4.5.1
186
+ rubygems_version: 2.4.8
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: HTTP should be easy