rest-client 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +27 -17
- data/README.md +149 -31
- data/history.md +9 -0
- data/lib/restclient/request.rb +20 -71
- data/lib/restclient/version.rb +1 -1
- data/rest-client.gemspec +1 -1
- data/spec/integration/httpbin_spec.rb +1 -1
- data/spec/unit/request_spec.rb +28 -50
- data/spec/unit/resource_spec.rb +5 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 164c2c41b4ec9185047a9c54005a4cda0d0b00a1
|
4
|
+
data.tar.gz: 0609bc767927170a96d36f44d01068333764a7f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 134a846db71895039df52e3b65709767f8234df3414f53665228944432f2b5b39eeb5399f1baed1baf47fcd16d031ac5dbb442140e9381175c6c6192170848b8
|
7
|
+
data.tar.gz: 69cedd07d3fc17d5e983fd264ef38517ea8233fa0f5c9de3f1ffc06f33b2b4902f07d673eb26f6aaca2fe29e3e474f5555f3dec5efb04330df7f4ceadc7316fa
|
data/.travis.yml
CHANGED
@@ -1,43 +1,53 @@
|
|
1
1
|
# Available ruby versions: http://rubies.travis-ci.org/
|
2
2
|
|
3
3
|
language: ruby
|
4
|
+
|
4
5
|
os:
|
5
6
|
- linux
|
6
7
|
- osx
|
8
|
+
|
7
9
|
rvm:
|
8
10
|
- "2.0.0"
|
9
11
|
- "2.1" # latest 2.1.x
|
10
|
-
- "2.2"
|
11
|
-
- "2.3.
|
12
|
+
- "2.2.5"
|
13
|
+
- "2.3.3"
|
14
|
+
- "2.4.0"
|
12
15
|
- "ruby-head"
|
13
16
|
- "jruby-9.0.5.0"
|
17
|
+
- "jruby-9.1.5.0"
|
14
18
|
- "jruby-head"
|
19
|
+
|
15
20
|
script:
|
16
21
|
bundle exec rake test
|
22
|
+
|
17
23
|
branches:
|
18
24
|
except:
|
19
25
|
- "readme-edits"
|
20
26
|
|
27
|
+
before_install:
|
28
|
+
- gem update --system
|
29
|
+
# bundler installation needed for jruby-head
|
30
|
+
# https://github.com/travis-ci/travis-ci/issues/5861
|
31
|
+
- gem install bundler
|
32
|
+
|
21
33
|
# Travis OS X support is pretty janky. These are some hacks to include tests
|
22
34
|
# only on versions that actually work.
|
23
|
-
# (last tested: 2016-
|
35
|
+
# (last tested: 2016-11)
|
24
36
|
matrix:
|
25
|
-
exclude:
|
26
|
-
|
27
|
-
|
28
|
-
- os: osx
|
29
|
-
rvm: '2.3.1' # No 2.3.x at all
|
30
|
-
include:
|
31
|
-
- os: osx
|
32
|
-
rvm: '2.2.2' # Travis OS X doesn't have 2.2 aliases
|
37
|
+
# exclude: {}
|
38
|
+
# include: {}
|
39
|
+
|
33
40
|
allow_failures:
|
34
41
|
- rvm: 'ruby-head'
|
35
|
-
|
36
|
-
|
37
|
-
- os: osx
|
38
|
-
rvm: 'jruby-head'
|
39
|
-
- os: linux
|
40
|
-
rvm: 'jruby-head'
|
42
|
+
|
43
|
+
# return results as soon as mandatory versions are done
|
41
44
|
fast_finish: true
|
42
45
|
|
43
46
|
sudo: false
|
47
|
+
|
48
|
+
|
49
|
+
# Use Java 8 for jruby to fix some Java 7 bugs.
|
50
|
+
addons:
|
51
|
+
apt:
|
52
|
+
packages:
|
53
|
+
- oracle-java8-set-default
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# REST Client -- simple DSL for accessing HTTP and REST resources
|
2
2
|
|
3
|
-
[![Gem Downloads](https://img.shields.io/gem/dt/
|
3
|
+
[![Gem Downloads](https://img.shields.io/gem/dt/rest-client.svg)](https://rubygems.org/gems/rest-client)
|
4
4
|
[![Build Status](https://travis-ci.org/rest-client/rest-client.svg?branch=master)](https://travis-ci.org/rest-client/rest-client)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/rest-client/rest-client.svg)](https://codeclimate.com/github/rest-client/rest-client)
|
6
6
|
[![Inline docs](http://inch-ci.org/github/rest-client/rest-client.svg?branch=master)](http://www.rubydoc.info/github/rest-client/rest-client/master)
|
@@ -75,30 +75,48 @@ Overview of significant changes:
|
|
75
75
|
See [history.md](./history.md) for a more complete description of changes.
|
76
76
|
|
77
77
|
## Usage: Raw URL
|
78
|
+
|
79
|
+
Basic usage:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
require 'rest-client'
|
83
|
+
|
84
|
+
RestClient.get(url, headers={})
|
85
|
+
|
86
|
+
RestClient.post(url, payload, headers={})
|
87
|
+
```
|
88
|
+
|
89
|
+
In the high level helpers, only POST, PATCH, and PUT take a payload argument.
|
90
|
+
To pass a payload with other HTTP verbs or to pass more advanced options, use
|
91
|
+
`RestClient::Request.execute` instead.
|
92
|
+
|
93
|
+
More detailed examples:
|
94
|
+
|
78
95
|
```ruby
|
79
96
|
require 'rest-client'
|
80
97
|
|
81
98
|
RestClient.get 'http://example.com/resource'
|
82
99
|
|
83
|
-
RestClient.get 'http://example.com/resource', {:
|
100
|
+
RestClient.get 'http://example.com/resource', {params: {id: 50, 'foo' => 'bar'}}
|
84
101
|
|
85
|
-
RestClient.get 'https://user:password@example.com/private/resource', {:
|
102
|
+
RestClient.get 'https://user:password@example.com/private/resource', {accept: :json}
|
86
103
|
|
87
|
-
RestClient.post 'http://example.com/resource', :
|
104
|
+
RestClient.post 'http://example.com/resource', {param1: 'one', nested: {param2: 'two'}}
|
88
105
|
|
89
|
-
RestClient.post "http://example.com/resource", {
|
106
|
+
RestClient.post "http://example.com/resource", {'x' => 1}.to_json, {content_type: :json, accept: :json}
|
90
107
|
|
91
108
|
RestClient.delete 'http://example.com/resource'
|
92
109
|
|
93
|
-
response = RestClient.get 'http://example.com/resource'
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
110
|
+
>> response = RestClient.get 'http://example.com/resource'
|
111
|
+
=> <RestClient::Response 200 "<!doctype h...">
|
112
|
+
>> response.code
|
113
|
+
=> 200
|
114
|
+
>> response.cookies
|
115
|
+
=> {"Foo"=>"BAR", "QUUX"=>"QUUUUX"}
|
116
|
+
>> response.headers
|
117
|
+
=> {:content_type=>"text/html; charset=utf-8", :cache_control=>"private" ... }
|
118
|
+
>> response.body
|
119
|
+
=> "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n ..."
|
102
120
|
|
103
121
|
RestClient.post( url,
|
104
122
|
{
|
@@ -191,21 +209,44 @@ See `RestClient::Resource` docs for details.
|
|
191
209
|
- for result codes between `200` and `207`, a `RestClient::Response` will be returned
|
192
210
|
- for result codes `301`, `302` or `307`, the redirection will be followed if the request is a `GET` or a `HEAD`
|
193
211
|
- for result code `303`, the redirection will be followed and the request transformed into a `GET`
|
194
|
-
- for other cases, a `RestClient::
|
212
|
+
- for other cases, a `RestClient::ExceptionWithResponse` holding the Response will be raised; a specific exception class will be thrown for known error codes
|
195
213
|
- call `.response` on the exception to get the server's response
|
196
214
|
|
197
215
|
```ruby
|
198
|
-
RestClient.get 'http://example.com/
|
199
|
-
|
216
|
+
>> RestClient.get 'http://example.com/nonexistent'
|
217
|
+
Exception: RestClient::NotFound: 404 Not Found
|
200
218
|
|
201
|
-
begin
|
202
|
-
|
203
|
-
rescue => e
|
204
|
-
|
205
|
-
end
|
206
|
-
|
219
|
+
>> begin
|
220
|
+
RestClient.get 'http://example.com/nonexistent'
|
221
|
+
rescue RestClient::ExceptionWithResponse => e
|
222
|
+
e.response
|
223
|
+
end
|
224
|
+
=> <RestClient::Response 404 "<!doctype h...">
|
207
225
|
```
|
208
226
|
|
227
|
+
### Other exceptions
|
228
|
+
|
229
|
+
While most exceptions have been collected under `RestClient::RequestFailed` aka
|
230
|
+
`RestClient::ExceptionWithResponse`, there are a few quirky exceptions that
|
231
|
+
have been kept for backwards compatibility.
|
232
|
+
|
233
|
+
RestClient will propagate up exceptions like socket errors without modification:
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
>> RestClient.get 'http://localhost:12345'
|
237
|
+
Exception: Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 12345
|
238
|
+
```
|
239
|
+
|
240
|
+
RestClient handles a few specific error cases separately in order to give
|
241
|
+
better error messages. These will hopefully be cleaned up in a future major
|
242
|
+
release.
|
243
|
+
|
244
|
+
`RestClient::ServerBrokeConnection` is translated from `EOFError` to give a
|
245
|
+
better error message.
|
246
|
+
|
247
|
+
`RestClient::SSLCertificateNotVerified` is raised when HTTPS validation fails.
|
248
|
+
Other `OpenSSL::SSL::SSLError` errors are raised as is.
|
249
|
+
|
209
250
|
### Redirection
|
210
251
|
|
211
252
|
By default, rest-client will follow HTTP 30x redirection requests.
|
@@ -297,18 +338,20 @@ end
|
|
297
338
|
➔ <RestClient::Response 404 "<!doctype h...">
|
298
339
|
```
|
299
340
|
|
300
|
-
### Response callbacks
|
341
|
+
### Response callbacks, error handling
|
301
342
|
|
302
343
|
A block can be passed to the RestClient method. This block will then be called with the Response.
|
303
344
|
Response.return! can be called to invoke the default response's behavior.
|
304
345
|
|
305
346
|
```ruby
|
306
347
|
# Don't raise exceptions but return the response
|
307
|
-
RestClient.get('http://example.com/
|
308
|
-
|
348
|
+
>> RestClient.get('http://example.com/nonexistent') {|response, request, result| response }
|
349
|
+
=> <RestClient::Response 404 "<!doctype h...">
|
350
|
+
```
|
309
351
|
|
352
|
+
```ruby
|
310
353
|
# Manage a specific error code
|
311
|
-
RestClient.get('http://
|
354
|
+
RestClient.get('http://example.com/resource') { |response, request, result, &block|
|
312
355
|
case response.code
|
313
356
|
when 200
|
314
357
|
p "It worked !"
|
@@ -319,19 +362,68 @@ RestClient.get('http://my-rest-service.com/resource'){ |response, request, resul
|
|
319
362
|
response.return!(request, result, &block)
|
320
363
|
end
|
321
364
|
}
|
365
|
+
```
|
366
|
+
|
367
|
+
But note that it may be more straightforward to use exceptions to handle
|
368
|
+
different HTTP error response cases:
|
369
|
+
|
370
|
+
```ruby
|
371
|
+
begin
|
372
|
+
resp = RestClient.get('http://example.com/resource')
|
373
|
+
rescue RestClient::Unauthorized, RestClient::Forbidden => err
|
374
|
+
puts 'Access denied'
|
375
|
+
return err.response
|
376
|
+
rescue RestClient::ImATeapot => err
|
377
|
+
puts 'The server is a teapot! # RFC 2324'
|
378
|
+
return err.response
|
379
|
+
else
|
380
|
+
puts 'It worked!'
|
381
|
+
return resp
|
382
|
+
end
|
383
|
+
```
|
384
|
+
|
385
|
+
For GET and HEAD requests, rest-client automatically follows redirection. For
|
386
|
+
other HTTP verbs, call `.follow_redirection` on the response object (works both
|
387
|
+
in block form and in exception form).
|
322
388
|
|
389
|
+
```ruby
|
323
390
|
# Follow redirections for all request types and not only for get and head
|
324
391
|
# RFC : "If the 301, 302 or 307 status code is received in response to a request other than GET or HEAD,
|
325
392
|
# the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user,
|
326
393
|
# since this might change the conditions under which the request was issued."
|
327
|
-
|
328
|
-
|
329
|
-
|
394
|
+
|
395
|
+
# block style
|
396
|
+
RestClient.post('http://example.com/redirect', 'body') { |response, request, result|
|
397
|
+
case response.code
|
398
|
+
when 301, 302, 307
|
399
|
+
response.follow_redirection
|
330
400
|
else
|
331
|
-
response.return!
|
401
|
+
response.return!
|
332
402
|
end
|
333
403
|
}
|
404
|
+
|
405
|
+
# exception style by explicit classes
|
406
|
+
begin
|
407
|
+
RestClient.post('http://example.com/redirect', 'body')
|
408
|
+
rescue RestClient::MovedPermanently,
|
409
|
+
RestClient::Found,
|
410
|
+
RestClient::TemporaryRedirect => err
|
411
|
+
err.response.follow_redirection
|
412
|
+
end
|
413
|
+
|
414
|
+
# exception style by response code
|
415
|
+
begin
|
416
|
+
RestClient.post('http://example.com/redirect', 'body')
|
417
|
+
rescue RestClient::ExceptionWithResponse => err
|
418
|
+
case err.http_code
|
419
|
+
when 301, 302, 307
|
420
|
+
err.response.follow_redirection
|
421
|
+
else
|
422
|
+
raise
|
423
|
+
end
|
424
|
+
end
|
334
425
|
```
|
426
|
+
|
335
427
|
## Non-normalized URIs
|
336
428
|
|
337
429
|
If you need to normalize URIs, e.g. to work with International Resource Identifiers (IRIs),
|
@@ -509,6 +601,14 @@ Basic `x-www-form-urlencoded` POST params:
|
|
509
601
|
"url"=>"https://httpbin.org/post"}
|
510
602
|
```
|
511
603
|
|
604
|
+
JSON payload: rest-client does not speak JSON natively, so serialize your
|
605
|
+
payload to a string before passing it to rest-client.
|
606
|
+
```ruby
|
607
|
+
>> payload = {'name' => 'newrepo', 'description': 'A new repo'}
|
608
|
+
>> RestClient.post('https://api.github.com/user/repos', payload.to_json, content_type: :json)
|
609
|
+
=> <RestClient::Response 201 "{\"id\":75149...">
|
610
|
+
```
|
611
|
+
|
512
612
|
Advanced GET params (arrays):
|
513
613
|
```ruby
|
514
614
|
>> r = RestClient.get('https://http-params.herokuapp.com/get', params: {foo: [1,2,3]})
|
@@ -571,6 +671,24 @@ RestClient.post 'http://example.com/resource', {:foo => 'bar', :baz => 'qux'}, {
|
|
571
671
|
RestClient.delete 'http://example.com/resource', {:Authorization => 'Bearer cT0febFoD5lxAlNAXHo6g'}
|
572
672
|
```
|
573
673
|
|
674
|
+
## Timeouts
|
675
|
+
|
676
|
+
By default the timeout for a request is 60 seconds. Timeouts for your request can
|
677
|
+
be adjusted by setting the `timeout:` to the number of seconds that you would like
|
678
|
+
the request to wait. Setting `timeout:` will override both `read_timeout:` and `open_timeout:`.
|
679
|
+
|
680
|
+
```ruby
|
681
|
+
RestClient::Request.execute(method: :get, url: 'http://example.com/resource',
|
682
|
+
timeout: 120)
|
683
|
+
```
|
684
|
+
|
685
|
+
Additionally, you can set `read_timeout:` and `open_timeout:` separately.
|
686
|
+
|
687
|
+
```ruby
|
688
|
+
RestClient::Request.execute(method: :get, url: 'http://example.com/resource',
|
689
|
+
read_timeout: 120, open_timeout: 240)
|
690
|
+
```
|
691
|
+
|
574
692
|
## Cookies
|
575
693
|
|
576
694
|
Request and Response objects know about HTTP cookies, and will automatically
|
data/history.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 2.0.1
|
2
|
+
|
3
|
+
- Warn if auto-generated headers from the payload, such as Content-Type,
|
4
|
+
override headers set by the user. This is usually not what the user wants to
|
5
|
+
happen, and can be surprising. (#554)
|
6
|
+
- Drop the old check for weak default TLS ciphers, and use the built-in Ruby
|
7
|
+
defaults. Ruby versions from Oct. 2014 onward use sane defaults, so this is
|
8
|
+
no longer needed. (#573)
|
9
|
+
|
1
10
|
# 2.0.0
|
2
11
|
|
3
12
|
This release is largely API compatible, but makes several breaking changes.
|
data/lib/restclient/request.rb
CHANGED
@@ -52,67 +52,6 @@ module RestClient
|
|
52
52
|
new(args).execute(& block)
|
53
53
|
end
|
54
54
|
|
55
|
-
# This is similar to the list now in ruby core, but adds HIGH for better
|
56
|
-
# compatibility (similar to Firefox) and moves AES-GCM cipher suites above
|
57
|
-
# DHE/ECDHE CBC suites (similar to Chromium).
|
58
|
-
# https://github.com/ruby/ruby/commit/699b209cf8cf11809620e12985ad33ae33b119ee
|
59
|
-
#
|
60
|
-
# This list will be used by default if the Ruby global OpenSSL default
|
61
|
-
# ciphers appear to be a weak list.
|
62
|
-
#
|
63
|
-
# TODO: either remove this code or always use it, since Ruby uses a decent
|
64
|
-
# cipher list in versions >= 2.0.
|
65
|
-
#
|
66
|
-
DefaultCiphers = %w{
|
67
|
-
!aNULL
|
68
|
-
!eNULL
|
69
|
-
!EXPORT
|
70
|
-
!SSLV2
|
71
|
-
!LOW
|
72
|
-
|
73
|
-
ECDHE-ECDSA-AES128-GCM-SHA256
|
74
|
-
ECDHE-RSA-AES128-GCM-SHA256
|
75
|
-
ECDHE-ECDSA-AES256-GCM-SHA384
|
76
|
-
ECDHE-RSA-AES256-GCM-SHA384
|
77
|
-
DHE-RSA-AES128-GCM-SHA256
|
78
|
-
DHE-DSS-AES128-GCM-SHA256
|
79
|
-
DHE-RSA-AES256-GCM-SHA384
|
80
|
-
DHE-DSS-AES256-GCM-SHA384
|
81
|
-
AES128-GCM-SHA256
|
82
|
-
AES256-GCM-SHA384
|
83
|
-
ECDHE-ECDSA-AES128-SHA256
|
84
|
-
ECDHE-RSA-AES128-SHA256
|
85
|
-
ECDHE-ECDSA-AES128-SHA
|
86
|
-
ECDHE-RSA-AES128-SHA
|
87
|
-
ECDHE-ECDSA-AES256-SHA384
|
88
|
-
ECDHE-RSA-AES256-SHA384
|
89
|
-
ECDHE-ECDSA-AES256-SHA
|
90
|
-
ECDHE-RSA-AES256-SHA
|
91
|
-
DHE-RSA-AES128-SHA256
|
92
|
-
DHE-RSA-AES256-SHA256
|
93
|
-
DHE-RSA-AES128-SHA
|
94
|
-
DHE-RSA-AES256-SHA
|
95
|
-
DHE-DSS-AES128-SHA256
|
96
|
-
DHE-DSS-AES256-SHA256
|
97
|
-
DHE-DSS-AES128-SHA
|
98
|
-
DHE-DSS-AES256-SHA
|
99
|
-
AES128-SHA256
|
100
|
-
AES256-SHA256
|
101
|
-
AES128-SHA
|
102
|
-
AES256-SHA
|
103
|
-
ECDHE-ECDSA-RC4-SHA
|
104
|
-
ECDHE-RSA-RC4-SHA
|
105
|
-
RC4-SHA
|
106
|
-
|
107
|
-
HIGH
|
108
|
-
+RC4
|
109
|
-
}.join(":")
|
110
|
-
|
111
|
-
# A set of weak default ciphers that we will override by default.
|
112
|
-
WeakDefaultCiphers = Set.new([
|
113
|
-
"ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW",
|
114
|
-
])
|
115
|
-
|
116
55
|
SSLOptionList = %w{client_cert client_key ca_file ca_path cert_store
|
117
56
|
version ciphers verify_callback verify_callback_warnings}
|
118
57
|
|
@@ -190,15 +129,6 @@ module RestClient
|
|
190
129
|
if !ssl_ca_file && !ssl_ca_path && !@ssl_opts.include?(:cert_store)
|
191
130
|
@ssl_opts[:cert_store] = self.class.default_ssl_cert_store
|
192
131
|
end
|
193
|
-
|
194
|
-
unless @ssl_opts.include?(:ciphers)
|
195
|
-
# If we're on a Ruby version that has insecure default ciphers,
|
196
|
-
# override it with our default list.
|
197
|
-
if WeakDefaultCiphers.include?(
|
198
|
-
OpenSSL::SSL::SSLContext::DEFAULT_PARAMS.fetch(:ciphers))
|
199
|
-
@ssl_opts[:ciphers] = DefaultCiphers
|
200
|
-
end
|
201
|
-
end
|
202
132
|
end
|
203
133
|
|
204
134
|
@tf = nil # If you are a raw request, this is your tempfile
|
@@ -432,7 +362,26 @@ module RestClient
|
|
432
362
|
#
|
433
363
|
def make_headers(user_headers)
|
434
364
|
headers = stringify_headers(default_headers).merge(stringify_headers(user_headers))
|
435
|
-
|
365
|
+
|
366
|
+
# override headers from the payload (e.g. Content-Type, Content-Length)
|
367
|
+
if @payload
|
368
|
+
payload_headers = @payload.headers
|
369
|
+
|
370
|
+
# Warn the user if we override any headers that were previously
|
371
|
+
# present. This usually indicates that rest-client was passed
|
372
|
+
# conflicting information, e.g. if it was asked to render a payload as
|
373
|
+
# x-www-form-urlencoded but a Content-Type application/json was
|
374
|
+
# also supplied by the user.
|
375
|
+
payload_headers.each_pair do |key, val|
|
376
|
+
if headers.include?(key)
|
377
|
+
warn("warning: Overriding #{key.inspect} header " +
|
378
|
+
"#{headers.fetch(key).inspect} with #{val.inspect} " +
|
379
|
+
"due to payload")
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
headers.merge!(payload_headers)
|
384
|
+
end
|
436
385
|
|
437
386
|
# merge in cookies
|
438
387
|
cookies = make_cookie_header
|
data/lib/restclient/version.rb
CHANGED
data/rest-client.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_development_dependency('rspec', '~> 3.0')
|
21
21
|
s.add_development_dependency('pry', '~> 0')
|
22
22
|
s.add_development_dependency('pry-doc', '~> 0')
|
23
|
-
s.add_development_dependency('rdoc', '>= 2.4.2', '<
|
23
|
+
s.add_development_dependency('rdoc', '>= 2.4.2', '< 6.0')
|
24
24
|
s.add_development_dependency('rubocop', '~> 0')
|
25
25
|
|
26
26
|
s.add_dependency('http-cookie', '>= 1.0.2', '< 2.0')
|
@@ -13,7 +13,7 @@ describe RestClient::Request do
|
|
13
13
|
def default_httpbin_url
|
14
14
|
# add a hack to work around java/jruby bug
|
15
15
|
# java.lang.RuntimeException: Could not generate DH keypair with backtrace
|
16
|
-
if
|
16
|
+
if ['jruby-19mode', 'jruby-9.0.5.0'].include?(ENV['TRAVIS_RUBY_VERSION'])
|
17
17
|
'http://httpbin.org/'
|
18
18
|
else
|
19
19
|
'https://httpbin.org/'
|
data/spec/unit/request_spec.rb
CHANGED
@@ -260,6 +260,34 @@ describe RestClient::Request, :include_helpers do
|
|
260
260
|
end
|
261
261
|
end
|
262
262
|
|
263
|
+
it 'warns when overriding existing headers via payload' do
|
264
|
+
expect(fake_stderr {
|
265
|
+
RestClient::Request.new(method: :post, url: 'example.com',
|
266
|
+
payload: {'foo' => 1}, headers: {content_type: :json})
|
267
|
+
}).to match(/warning: Overriding "Content-Type" header/i)
|
268
|
+
expect(fake_stderr {
|
269
|
+
RestClient::Request.new(method: :post, url: 'example.com',
|
270
|
+
payload: {'foo' => 1}, headers: {'Content-Type' => 'application/json'})
|
271
|
+
}).to match(/warning: Overriding "Content-Type" header/i)
|
272
|
+
|
273
|
+
expect(fake_stderr {
|
274
|
+
RestClient::Request.new(method: :post, url: 'example.com',
|
275
|
+
payload: '123456', headers: {content_length: '20'})
|
276
|
+
}).to match(/warning: Overriding "Content-Length" header/i)
|
277
|
+
expect(fake_stderr {
|
278
|
+
RestClient::Request.new(method: :post, url: 'example.com',
|
279
|
+
payload: '123456', headers: {'Content-Length' => '20'})
|
280
|
+
}).to match(/warning: Overriding "Content-Length" header/i)
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'does not warn for a normal looking payload' do
|
284
|
+
expect(fake_stderr {
|
285
|
+
RestClient::Request.new(method: :post, url: 'example.com', payload: 'payload')
|
286
|
+
RestClient::Request.new(method: :post, url: 'example.com', payload: 'payload', headers: {content_type: :json})
|
287
|
+
RestClient::Request.new(method: :post, url: 'example.com', payload: {'foo' => 'bar'})
|
288
|
+
}).to eq ''
|
289
|
+
end
|
290
|
+
|
263
291
|
it "uses netrc credentials" do
|
264
292
|
expect(Netrc).to receive(:read).and_return('example.com' => ['a', 'b'])
|
265
293
|
request = RestClient::Request.new(:method => :put, :url => 'http://example.com/', :payload => 'payload')
|
@@ -898,56 +926,6 @@ describe RestClient::Request, :include_helpers do
|
|
898
926
|
@request.send(:transmit, @uri, 'req', 'payload')
|
899
927
|
end
|
900
928
|
|
901
|
-
it "should override ssl_ciphers with better defaults with weak default ciphers" do
|
902
|
-
stub_const(
|
903
|
-
'::OpenSSL::SSL::SSLContext::DEFAULT_PARAMS',
|
904
|
-
{
|
905
|
-
:ssl_version=>"SSLv23",
|
906
|
-
:verify_mode=>1,
|
907
|
-
:ciphers=>"ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW",
|
908
|
-
:options=>-2147480577,
|
909
|
-
}
|
910
|
-
)
|
911
|
-
|
912
|
-
@request = RestClient::Request.new(
|
913
|
-
:method => :put,
|
914
|
-
:url => 'https://some/resource',
|
915
|
-
:payload => 'payload',
|
916
|
-
)
|
917
|
-
|
918
|
-
expect(@net).to receive(:ciphers=).with(RestClient::Request::DefaultCiphers)
|
919
|
-
|
920
|
-
allow(@http).to receive(:request)
|
921
|
-
allow(@request).to receive(:process_result)
|
922
|
-
allow(@request).to receive(:response_log)
|
923
|
-
@request.send(:transmit, @uri, 'req', 'payload')
|
924
|
-
end
|
925
|
-
|
926
|
-
it "should not override ssl_ciphers with better defaults with different default ciphers" do
|
927
|
-
stub_const(
|
928
|
-
'::OpenSSL::SSL::SSLContext::DEFAULT_PARAMS',
|
929
|
-
{
|
930
|
-
:ssl_version=>"SSLv23",
|
931
|
-
:verify_mode=>1,
|
932
|
-
:ciphers=>"HIGH:!aNULL:!eNULL:!EXPORT:!LOW:!MEDIUM:!SSLv2",
|
933
|
-
:options=>-2147480577,
|
934
|
-
}
|
935
|
-
)
|
936
|
-
|
937
|
-
@request = RestClient::Request.new(
|
938
|
-
:method => :put,
|
939
|
-
:url => 'https://some/resource',
|
940
|
-
:payload => 'payload',
|
941
|
-
)
|
942
|
-
|
943
|
-
expect(@net).not_to receive(:ciphers=)
|
944
|
-
|
945
|
-
allow(@http).to receive(:request)
|
946
|
-
allow(@request).to receive(:process_result)
|
947
|
-
allow(@request).to receive(:response_log)
|
948
|
-
@request.send(:transmit, @uri, 'req', 'payload')
|
949
|
-
end
|
950
|
-
|
951
929
|
it "should set the ssl_client_cert if provided" do
|
952
930
|
@request = RestClient::Request.new(
|
953
931
|
:method => :put,
|
data/spec/unit/resource_spec.rb
CHANGED
@@ -94,7 +94,11 @@ describe RestClient::Resource do
|
|
94
94
|
expect(parent.send(:[], 'posts', &block2).block).not_to eq block1
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
# Test fails on jruby 9.1.[0-5].* due to
|
98
|
+
# https://github.com/jruby/jruby/issues/4217
|
99
|
+
it "the block should be overrideable in ruby 1.9 syntax",
|
100
|
+
:unless => (RUBY_ENGINE == 'jruby' && JRUBY_VERSION =~ /\A9\.1\.[0-5]\./) \
|
101
|
+
do
|
98
102
|
block1 = proc {|r| r}
|
99
103
|
block2 = ->(r) {}
|
100
104
|
|
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.
|
4
|
+
version: 2.0.1
|
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:
|
11
|
+
date: 2017-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webmock
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
version: 2.4.2
|
76
76
|
- - "<"
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version: '
|
78
|
+
version: '6.0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -85,7 +85,7 @@ dependencies:
|
|
85
85
|
version: 2.4.2
|
86
86
|
- - "<"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
88
|
+
version: '6.0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rubocop
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -244,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
244
244
|
version: '0'
|
245
245
|
requirements: []
|
246
246
|
rubyforge_project:
|
247
|
-
rubygems_version: 2.
|
247
|
+
rubygems_version: 2.5.1
|
248
248
|
signing_key:
|
249
249
|
specification_version: 4
|
250
250
|
summary: Simple HTTP and REST client for Ruby, inspired by microframework syntax for
|
@@ -280,4 +280,3 @@ test_files:
|
|
280
280
|
- spec/unit/restclient_spec.rb
|
281
281
|
- spec/unit/utils_spec.rb
|
282
282
|
- spec/unit/windows/root_certs_spec.rb
|
283
|
-
has_rdoc:
|