rest-client 2.0.0.rc3 → 2.0.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/history.md +12 -5
- data/lib/restclient/request.rb +4 -2
- data/lib/restclient/version.rb +1 -1
- data/spec/integration/httpbin_spec.rb +14 -0
- data/spec/unit/request_spec.rb +22 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68b80b5b33ba926c8c3a2b4c0aac27b4e7f756f0
|
4
|
+
data.tar.gz: ba56b4b86dc27028889674a840132c6f88671f9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c83b06c417fd471f0c80ad5a7f93c645a5748ebec48785269c8af59e198c8cb9b7b6b52c0c36be48c6c9c0cee61e9faacafe5e4012ca8be655b0edf739d0b799
|
7
|
+
data.tar.gz: cea931e95b38351d4c6236189fbb781a1f2e0067eb95e3d65d94bae1eddeff7217158d1a3ca5875747371d7ceb5cd98fe2cb3fd0e189ed0db322cc913c1428b8
|
data/README.md
CHANGED
@@ -177,6 +177,38 @@ end
|
|
177
177
|
➔ 404 Resource Not Found | text/html 282 bytes
|
178
178
|
```
|
179
179
|
|
180
|
+
### Manually following redirection
|
181
|
+
|
182
|
+
To disable automatic redirection, set `:max_redirects => 0`.
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
>> RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1')
|
186
|
+
=> RestClient::Response 200 "{\n "args":..."
|
187
|
+
|
188
|
+
>> RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1', max_redirects: 0)
|
189
|
+
RestClient::Found: 302 Found
|
190
|
+
```
|
191
|
+
|
192
|
+
To manually follow redirection, you can call `Response#follow_redirection`. Or
|
193
|
+
you could of course inspect the result and choose custom behavior.
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
>> RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1', max_redirects: 0)
|
197
|
+
RestClient::Found: 302 Found
|
198
|
+
>> begin
|
199
|
+
RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1', max_redirects: 0)
|
200
|
+
rescue RestClient::ExceptionWithResponse => err
|
201
|
+
end
|
202
|
+
>> err
|
203
|
+
=> #<RestClient::Found: 302 Found>
|
204
|
+
>> err.response
|
205
|
+
=> RestClient::Response 302 "<!DOCTYPE H..."
|
206
|
+
>> err.response.headers[:location]
|
207
|
+
=> "/get"
|
208
|
+
>> err.response.follow_redirection
|
209
|
+
=> RestClient::Response 200 "{\n "args":..."
|
210
|
+
```
|
211
|
+
|
180
212
|
## Result handling
|
181
213
|
|
182
214
|
The result of a `RestClient::Request` is a `RestClient::Response` object.
|
data/history.md
CHANGED
@@ -8,7 +8,7 @@ This release is largely API compatible, but makes several breaking changes.
|
|
8
8
|
rest-client would not override the string encoding chosen by Net::HTTP. Now
|
9
9
|
responses that specify a charset will yield a body string in that encoding.
|
10
10
|
For example, `Content-Type: text/plain; charset=EUC-JP` will return a String
|
11
|
-
encoded with `Encoding::EUC_JP`.
|
11
|
+
encoded with `Encoding::EUC_JP`. (#361)
|
12
12
|
- Change exceptions raised on request timeout. Instead of
|
13
13
|
`RestClient::RequestTimeout` (which is still used for HTTP 408), network
|
14
14
|
timeouts will now raise either `RestClient::Exceptions::ReadTimeout` or
|
@@ -48,8 +48,8 @@ This release is largely API compatible, but makes several breaking changes.
|
|
48
48
|
Set-Cookie, which is special) by joining the values with a comma space,
|
49
49
|
compliant with RFC 7230
|
50
50
|
- Rewrite cookie support to be much smarter and to use cookie jars consistently
|
51
|
-
for requests, responses, and redirection
|
52
|
-
about the previously broken behavior)
|
51
|
+
for requests, responses, and redirection in order to resolve long-standing
|
52
|
+
complaints about the previously broken behavior: (#498)
|
53
53
|
- The `:cookies` option may now be a Hash of Strings, an Array of
|
54
54
|
HTTP::Cookie objects, or a full HTTP::CookieJar.
|
55
55
|
- Add `RestClient::Request#cookie_jar` and reimplement `Request#cookies` to
|
@@ -73,7 +73,7 @@ This release is largely API compatible, but makes several breaking changes.
|
|
73
73
|
treat any object that responds to `.read` as a streaming payload and pass it
|
74
74
|
through to `.body_stream=` on the Net:HTTP object. This massively reduces the
|
75
75
|
memory required for large file uploads.
|
76
|
-
- Changes to redirection behavior:
|
76
|
+
- Changes to redirection behavior: (#381, #484)
|
77
77
|
- Remove `RestClient::MaxRedirectsReached` in favor of the normal
|
78
78
|
`ExceptionWithResponse` subclasses. This makes the response accessible on
|
79
79
|
the exception object as `.response`, making it possible for callers to tell
|
@@ -90,7 +90,14 @@ This release is largely API compatible, but makes several breaking changes.
|
|
90
90
|
- Run tests on Travis's beta OS X support.
|
91
91
|
- Make `Request#transmit` a private method, along with a few others.
|
92
92
|
- Refactor URI parsing to happen earlier, in Request initialization.
|
93
|
-
-
|
93
|
+
- Improve consistency and functionality of complex URL parameter handling:
|
94
|
+
- When adding URL params, handle URLs that already contain params.
|
95
|
+
- Add new convention for handling URL params containing deeply nested arrays
|
96
|
+
and hashes, unify handling of null/empty values, and use the same code for
|
97
|
+
GET and POST params. (#437)
|
98
|
+
- Add the RestClient::ParamsArray class, a simple array-like container that
|
99
|
+
can be used to pass multiple keys with same name or keys where the ordering
|
100
|
+
is significant.
|
94
101
|
- Add a few more exception classes for obscure HTTP status codes.
|
95
102
|
- Multipart: use a much more robust multipart boundary with greater entropy.
|
96
103
|
- Make `RestClient::Payload::Base#inspect` stop pretending to be a String.
|
data/lib/restclient/request.rb
CHANGED
@@ -132,8 +132,10 @@ module RestClient
|
|
132
132
|
@cookie_jar = process_cookie_args!(@uri, @headers, args)
|
133
133
|
|
134
134
|
@payload = Payload.generate(args[:payload])
|
135
|
-
|
136
|
-
@
|
135
|
+
|
136
|
+
@user = args[:user] if args.include?(:user)
|
137
|
+
@password = args[:password] if args.include?(:password)
|
138
|
+
|
137
139
|
if args.include?(:timeout)
|
138
140
|
@read_timeout = args[:timeout]
|
139
141
|
@open_timeout = args[:timeout]
|
data/lib/restclient/version.rb
CHANGED
@@ -68,5 +68,19 @@ describe RestClient::Request do
|
|
68
68
|
expect(ex.response.cookies['foo']).to eq '"bar:baz"'
|
69
69
|
}
|
70
70
|
end
|
71
|
+
|
72
|
+
it 'sends basic auth' do
|
73
|
+
user = 'user'
|
74
|
+
pass = 'pass'
|
75
|
+
|
76
|
+
data = execute_httpbin_json("basic-auth/#{user}/#{pass}", method: :get, user: user, password: pass)
|
77
|
+
expect(data).to eq({'authenticated' => true, 'user' => user})
|
78
|
+
|
79
|
+
expect {
|
80
|
+
execute_httpbin_json("basic-auth/#{user}/#{pass}", method: :get, user: user, password: 'badpass')
|
81
|
+
}.to raise_error(RestClient::Unauthorized) { |ex|
|
82
|
+
expect(ex.http_code).to eq 401
|
83
|
+
}
|
84
|
+
end
|
71
85
|
end
|
72
86
|
end
|
data/spec/unit/request_spec.rb
CHANGED
@@ -103,25 +103,33 @@ describe RestClient::Request, :include_helpers do
|
|
103
103
|
|
104
104
|
describe "user - password" do
|
105
105
|
it "extracts the username and password when parsing http://user:password@example.com/" do
|
106
|
-
allow(URI).to receive(:parse).and_return(double('uri', user: 'joe', password: 'pass1', hostname: 'example.com'))
|
107
106
|
@request.send(:parse_url_with_auth!, 'http://joe:pass1@example.com/resource')
|
108
107
|
expect(@request.user).to eq 'joe'
|
109
108
|
expect(@request.password).to eq 'pass1'
|
110
109
|
end
|
111
110
|
|
112
111
|
it "extracts with escaping the username and password when parsing http://user:password@example.com/" do
|
113
|
-
allow(URI).to receive(:parse).and_return(double('uri', user: 'joe%20', password: 'pass1', hostname: 'example.com'))
|
114
112
|
@request.send(:parse_url_with_auth!, 'http://joe%20:pass1@example.com/resource')
|
115
113
|
expect(@request.user).to eq 'joe '
|
116
114
|
expect(@request.password).to eq 'pass1'
|
117
115
|
end
|
118
116
|
|
119
117
|
it "doesn't overwrite user and password (which may have already been set by the Resource constructor) if there is no user/password in the url" do
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
118
|
+
request = RestClient::Request.new(method: :get, url: 'http://example.com/resource', user: 'beth', password: 'pass2')
|
119
|
+
expect(request.user).to eq 'beth'
|
120
|
+
expect(request.password).to eq 'pass2'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'uses the username and password from the URL' do
|
124
|
+
request = RestClient::Request.new(method: :get, url: 'http://person:secret@example.com/resource')
|
125
|
+
expect(request.user).to eq 'person'
|
126
|
+
expect(request.password).to eq 'secret'
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'overrides URL user/pass with explicit options' do
|
130
|
+
request = RestClient::Request.new(method: :get, url: 'http://person:secret@example.com/resource', user: 'beth', password: 'pass2')
|
131
|
+
expect(request.user).to eq 'beth'
|
132
|
+
expect(request.password).to eq 'pass2'
|
125
133
|
end
|
126
134
|
end
|
127
135
|
|
@@ -253,19 +261,17 @@ describe RestClient::Request, :include_helpers do
|
|
253
261
|
end
|
254
262
|
|
255
263
|
it "uses netrc credentials" do
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
expect(
|
260
|
-
expect(@request.password).to eq 'b'
|
264
|
+
expect(Netrc).to receive(:read).and_return('example.com' => ['a', 'b'])
|
265
|
+
request = RestClient::Request.new(:method => :put, :url => 'http://example.com/', :payload => 'payload')
|
266
|
+
expect(request.user).to eq 'a'
|
267
|
+
expect(request.password).to eq 'b'
|
261
268
|
end
|
262
269
|
|
263
270
|
it "uses credentials in the url in preference to netrc" do
|
264
|
-
allow(URI).to receive(:parse).and_return(double('uri', :user => 'joe%20', :password => 'pass1', :hostname => 'example.com'))
|
265
271
|
allow(Netrc).to receive(:read).and_return('example.com' => ['a', 'b'])
|
266
|
-
|
267
|
-
expect(
|
268
|
-
expect(
|
272
|
+
request = RestClient::Request.new(:method => :put, :url => 'http://joe%20:pass1@example.com/', :payload => 'payload')
|
273
|
+
expect(request.user).to eq 'joe '
|
274
|
+
expect(request.password).to eq 'pass1'
|
269
275
|
end
|
270
276
|
|
271
277
|
it "determines the Net::HTTP class to instantiate by the method name" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- REST Client Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webmock
|