rest-client 1.7.3-x86-mingw32 → 1.8.0.rc1-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rest-client might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/restclient/abstract_response.rb +43 -14
- data/lib/restclient/raw_response.rb +3 -2
- data/lib/restclient/request.rb +2 -2
- data/lib/restclient/response.rb +2 -5
- data/lib/restclient/version.rb +1 -1
- data/rest-client.gemspec +1 -0
- data/spec/unit/abstract_response_spec.rb +6 -3
- data/spec/unit/raw_response_spec.rb +2 -1
- data/spec/unit/response_spec.rb +27 -18
- data/spec/unit/restclient_spec.rb +2 -2
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67a605ad9df5e5ffab7cfd4f699ac98f3f7d932c
|
4
|
+
data.tar.gz: 643e9f2417da7a64d0bc5b1bf2640869a0954265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25a88d9617727d50547f043b15caac64060b51e7ac46b0297464db656ed670652b5247add06e206e02053c2c81fce91a5a5273547df9b568c4dfd4035e2e1959
|
7
|
+
data.tar.gz: 709ac12e58ee9889d3e5cda11db54061ebda06ca2112e8a2ce02d768b5e2b2dfe244a77b42fa73ffd06bb395d68f5511f229cdfbcb9e1aea867615f18f001e6d
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'cgi'
|
2
|
+
require 'http-cookie'
|
2
3
|
|
3
4
|
module RestClient
|
4
5
|
|
5
6
|
module AbstractResponse
|
6
7
|
|
7
|
-
attr_reader :net_http_res, :args
|
8
|
+
attr_reader :net_http_res, :args, :request
|
8
9
|
|
9
10
|
# HTTP status code
|
10
11
|
def code
|
@@ -22,11 +23,36 @@ module RestClient
|
|
22
23
|
@raw_headers ||= @net_http_res.to_hash
|
23
24
|
end
|
24
25
|
|
26
|
+
def response_set_vars(net_http_res, args, request)
|
27
|
+
@net_http_res = net_http_res
|
28
|
+
@args = args
|
29
|
+
@request = request
|
30
|
+
end
|
31
|
+
|
25
32
|
# Hash of cookies extracted from response headers
|
26
33
|
def cookies
|
27
|
-
|
28
|
-
|
34
|
+
hash = {}
|
35
|
+
|
36
|
+
cookie_jar.cookies.each do |cookie|
|
37
|
+
hash[cookie.name] = cookie.value
|
29
38
|
end
|
39
|
+
|
40
|
+
hash
|
41
|
+
end
|
42
|
+
|
43
|
+
# Cookie jar extracted from response headers.
|
44
|
+
#
|
45
|
+
# @return [HTTP::CookieJar]
|
46
|
+
#
|
47
|
+
def cookie_jar
|
48
|
+
return @cookie_jar if @cookie_jar
|
49
|
+
|
50
|
+
jar = HTTP::CookieJar.new
|
51
|
+
headers.fetch(:set_cookie, []).each do |cookie|
|
52
|
+
jar.parse(cookie, @request.url)
|
53
|
+
end
|
54
|
+
|
55
|
+
@cookie_jar = jar
|
30
56
|
end
|
31
57
|
|
32
58
|
# Return the default behavior corresponding to the response code:
|
@@ -61,25 +87,28 @@ module RestClient
|
|
61
87
|
|
62
88
|
# Follow a redirection
|
63
89
|
def follow_redirection request = nil, result = nil, & block
|
90
|
+
new_args = @args.dup
|
91
|
+
|
64
92
|
url = headers[:location]
|
65
93
|
if url !~ /^http/
|
66
|
-
url = URI.parse(
|
94
|
+
url = URI.parse(request.url).merge(url).to_s
|
67
95
|
end
|
68
|
-
|
96
|
+
new_args[:url] = url
|
69
97
|
if request
|
70
98
|
if request.max_redirects == 0
|
71
99
|
raise MaxRedirectsReached
|
72
100
|
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
101
|
+
new_args[:password] = request.password
|
102
|
+
new_args[:user] = request.user
|
103
|
+
new_args[:headers] = request.headers
|
104
|
+
new_args[:max_redirects] = request.max_redirects - 1
|
105
|
+
|
106
|
+
# TODO: figure out what to do with original :cookie, :cookies values
|
107
|
+
new_args[:headers]['Cookie'] = HTTP::Cookie.cookie_value(
|
108
|
+
cookie_jar.cookies(new_args.fetch(:url)))
|
81
109
|
end
|
82
|
-
|
110
|
+
|
111
|
+
Request.execute(new_args, &block)
|
83
112
|
end
|
84
113
|
|
85
114
|
def self.beautify_headers(headers)
|
@@ -13,12 +13,13 @@ module RestClient
|
|
13
13
|
|
14
14
|
include AbstractResponse
|
15
15
|
|
16
|
-
attr_reader :file
|
16
|
+
attr_reader :file, :request
|
17
17
|
|
18
|
-
def initialize
|
18
|
+
def initialize(tempfile, net_http_res, args, request)
|
19
19
|
@net_http_res = net_http_res
|
20
20
|
@args = args
|
21
21
|
@file = tempfile
|
22
|
+
@request = request
|
22
23
|
end
|
23
24
|
|
24
25
|
def to_s
|
data/lib/restclient/request.rb
CHANGED
@@ -484,9 +484,9 @@ module RestClient
|
|
484
484
|
def process_result res, & block
|
485
485
|
if @raw_response
|
486
486
|
# We don't decode raw requests
|
487
|
-
response = RawResponse.new(@tf, res, args)
|
487
|
+
response = RawResponse.new(@tf, res, args, self)
|
488
488
|
else
|
489
|
-
response = Response.create(Request.decode(res['content-encoding'], res.body), res, args)
|
489
|
+
response = Response.create(Request.decode(res['content-encoding'], res.body), res, args, self)
|
490
490
|
end
|
491
491
|
|
492
492
|
if block_given?
|
data/lib/restclient/response.rb
CHANGED
@@ -6,17 +6,14 @@ module RestClient
|
|
6
6
|
|
7
7
|
include AbstractResponse
|
8
8
|
|
9
|
-
attr_accessor :args, :net_http_res
|
10
|
-
|
11
9
|
def body
|
12
10
|
self
|
13
11
|
end
|
14
12
|
|
15
|
-
def self.create body, net_http_res, args
|
13
|
+
def self.create body, net_http_res, args, request
|
16
14
|
result = body || ''
|
17
15
|
result.extend Response
|
18
|
-
result.net_http_res
|
19
|
-
result.args = args
|
16
|
+
result.response_set_vars(net_http_res, args, request)
|
20
17
|
result
|
21
18
|
end
|
22
19
|
|
data/lib/restclient/version.rb
CHANGED
data/rest-client.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency('pry-doc')
|
23
23
|
s.add_development_dependency('rdoc', '>= 2.4.2', '< 5.0')
|
24
24
|
|
25
|
+
s.add_dependency('http-cookie', '>= 1.0.2', '< 2.0')
|
25
26
|
s.add_dependency('mime-types', '>= 1.16', '< 3.0')
|
26
27
|
s.add_dependency('netrc', '~> 0.7')
|
27
28
|
|
@@ -8,16 +8,18 @@ describe RestClient::AbstractResponse do
|
|
8
8
|
|
9
9
|
attr_accessor :size
|
10
10
|
|
11
|
-
def initialize net_http_res, args
|
11
|
+
def initialize net_http_res, args, request
|
12
12
|
@net_http_res = net_http_res
|
13
13
|
@args = args
|
14
|
+
@request = request
|
14
15
|
end
|
15
16
|
|
16
17
|
end
|
17
18
|
|
18
19
|
before do
|
19
20
|
@net_http_res = double('net http response')
|
20
|
-
@
|
21
|
+
@request = double('restclient request', :url => 'http://example.com')
|
22
|
+
@response = MyAbstractResponse.new(@net_http_res, {}, @request)
|
21
23
|
end
|
22
24
|
|
23
25
|
it "fetches the numeric response code" do
|
@@ -53,7 +55,8 @@ describe RestClient::AbstractResponse do
|
|
53
55
|
|
54
56
|
it "extract strange cookies" do
|
55
57
|
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/'])
|
56
|
-
@response.
|
58
|
+
@response.headers.should eq({:set_cookie => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/']})
|
59
|
+
@response.cookies.should eq({ 'session_id' => 'ZJ/HQVH6YE+rVkTpn0zvTQ==' })
|
57
60
|
end
|
58
61
|
|
59
62
|
it "doesn't escape cookies" do
|
@@ -4,7 +4,8 @@ describe RestClient::RawResponse do
|
|
4
4
|
before do
|
5
5
|
@tf = double("Tempfile", :read => "the answer is 42", :open => true)
|
6
6
|
@net_http_res = double('net http response')
|
7
|
-
@
|
7
|
+
@request = double('http request')
|
8
|
+
@response = RestClient::RawResponse.new(@tf, @net_http_res, {}, @request)
|
8
9
|
end
|
9
10
|
|
10
11
|
it "behaves like string" do
|
data/spec/unit/response_spec.rb
CHANGED
@@ -3,8 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe RestClient::Response do
|
4
4
|
before do
|
5
5
|
@net_http_res = double('net http response', :to_hash => {"Status" => ["200 OK"]}, :code => 200)
|
6
|
-
@
|
7
|
-
@
|
6
|
+
@example_url = 'http://example.com'
|
7
|
+
@request = double('http request', :user => nil, :password => nil, :url => @example_url)
|
8
|
+
@response = RestClient::Response.create('abc', @net_http_res, {}, @request)
|
8
9
|
end
|
9
10
|
|
10
11
|
it "behaves like string" do
|
@@ -14,7 +15,7 @@ describe RestClient::Response do
|
|
14
15
|
end
|
15
16
|
|
16
17
|
it "accepts nil strings and sets it to empty for the case of HEAD" do
|
17
|
-
RestClient::Response.create(nil, @net_http_res, {}).to_s.should eq ""
|
18
|
+
RestClient::Response.create(nil, @net_http_res, {}, @request).to_s.should eq ""
|
18
19
|
end
|
19
20
|
|
20
21
|
it "test headers and raw headers" do
|
@@ -24,16 +25,18 @@ describe RestClient::Response do
|
|
24
25
|
|
25
26
|
describe "cookie processing" do
|
26
27
|
it "should correctly deal with one Set-Cookie header with one cookie inside" do
|
27
|
-
|
28
|
-
|
29
|
-
response
|
28
|
+
header_val = "main_page=main_page_no_rewrite; path=/; expires=Sat, 10-Jan-2037 15:03:14 GMT".freeze
|
29
|
+
|
30
|
+
net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => [header_val]})
|
31
|
+
response = RestClient::Response.create('abc', net_http_res, {}, @request)
|
32
|
+
response.headers[:set_cookie].should eq [header_val]
|
30
33
|
response.cookies.should eq({ "main_page" => "main_page_no_rewrite" })
|
31
34
|
end
|
32
35
|
|
33
36
|
it "should correctly deal with multiple cookies [multiple Set-Cookie headers]" do
|
34
|
-
net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=
|
35
|
-
response = RestClient::Response.create('abc', net_http_res, {})
|
36
|
-
response.headers[:set_cookie].should eq ["main_page=main_page_no_rewrite; path=/; expires=
|
37
|
+
net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=Sat, 10-Jan-2037 15:03:14 GMT", "remember_me=; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT", "user=somebody; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT"]})
|
38
|
+
response = RestClient::Response.create('abc', net_http_res, {}, @request)
|
39
|
+
response.headers[:set_cookie].should eq ["main_page=main_page_no_rewrite; path=/; expires=Sat, 10-Jan-2037 15:03:14 GMT", "remember_me=; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT", "user=somebody; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT"]
|
37
40
|
response.cookies.should eq({
|
38
41
|
"main_page" => "main_page_no_rewrite",
|
39
42
|
"remember_me" => "",
|
@@ -42,8 +45,8 @@ describe RestClient::Response do
|
|
42
45
|
end
|
43
46
|
|
44
47
|
it "should correctly deal with multiple cookies [one Set-Cookie header with multiple cookies]" do
|
45
|
-
net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=
|
46
|
-
response = RestClient::Response.create('abc', net_http_res, {})
|
48
|
+
net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=Sat, 10-Jan-2037 15:03:14 GMT, remember_me=; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT, user=somebody; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT"]})
|
49
|
+
response = RestClient::Response.create('abc', net_http_res, {}, @request)
|
47
50
|
response.cookies.should eq({
|
48
51
|
"main_page" => "main_page_no_rewrite",
|
49
52
|
"remember_me" => "",
|
@@ -56,7 +59,7 @@ describe RestClient::Response do
|
|
56
59
|
it "should return itself for normal codes" do
|
57
60
|
(200..206).each do |code|
|
58
61
|
net_http_res = double('net http response', :code => '200')
|
59
|
-
response = RestClient::Response.create('abc', net_http_res, {})
|
62
|
+
response = RestClient::Response.create('abc', net_http_res, {}, @request)
|
60
63
|
response.return! @request
|
61
64
|
end
|
62
65
|
end
|
@@ -65,7 +68,7 @@ describe RestClient::Response do
|
|
65
68
|
RestClient::Exceptions::EXCEPTIONS_MAP.each_key do |code|
|
66
69
|
unless (200..207).include? code
|
67
70
|
net_http_res = double('net http response', :code => code.to_i)
|
68
|
-
response = RestClient::Response.create('abc', net_http_res, {})
|
71
|
+
response = RestClient::Response.create('abc', net_http_res, {}, @request)
|
69
72
|
lambda { response.return!}.should raise_error
|
70
73
|
end
|
71
74
|
end
|
@@ -88,32 +91,38 @@ describe RestClient::Response do
|
|
88
91
|
end
|
89
92
|
|
90
93
|
it "follows a redirection and keep the cookies" do
|
94
|
+
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' => 'Foo=Bar', 'Location' => 'http://some/new_resource', })
|
95
|
+
stub_request(:get, 'http://some/new_resource').with(:headers => {'Cookie' => 'Foo=Bar'}).to_return(:body => 'Qux')
|
96
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Qux'
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'does not keep cookies across domains' do
|
91
100
|
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' => 'Foo=Bar', 'Location' => 'http://new/resource', })
|
92
|
-
stub_request(:get, 'http://new/resource').with(:headers => {'Cookie' => '
|
101
|
+
stub_request(:get, 'http://new/resource').with(:headers => {'Cookie' => ''}).to_return(:body => 'Qux')
|
93
102
|
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Qux'
|
94
103
|
end
|
95
104
|
|
96
105
|
it "doesn't follow a 301 when the request is a post" do
|
97
106
|
net_http_res = double('net http response', :code => 301)
|
98
|
-
response = RestClient::Response.create('abc', net_http_res, {:method => :post})
|
107
|
+
response = RestClient::Response.create('abc', net_http_res, {:method => :post}, @request)
|
99
108
|
lambda { response.return!(@request)}.should raise_error(RestClient::MovedPermanently)
|
100
109
|
end
|
101
110
|
|
102
111
|
it "doesn't follow a 302 when the request is a post" do
|
103
112
|
net_http_res = double('net http response', :code => 302)
|
104
|
-
response = RestClient::Response.create('abc', net_http_res, {:method => :post})
|
113
|
+
response = RestClient::Response.create('abc', net_http_res, {:method => :post}, @request)
|
105
114
|
lambda { response.return!(@request)}.should raise_error(RestClient::Found)
|
106
115
|
end
|
107
116
|
|
108
117
|
it "doesn't follow a 307 when the request is a post" do
|
109
118
|
net_http_res = double('net http response', :code => 307)
|
110
|
-
response = RestClient::Response.create('abc', net_http_res, {:method => :post})
|
119
|
+
response = RestClient::Response.create('abc', net_http_res, {:method => :post}, @request)
|
111
120
|
lambda { response.return!(@request)}.should raise_error(RestClient::TemporaryRedirect)
|
112
121
|
end
|
113
122
|
|
114
123
|
it "doesn't follow a redirection when the request is a put" do
|
115
124
|
net_http_res = double('net http response', :code => 301)
|
116
|
-
response = RestClient::Response.create('abc', net_http_res, {:method => :put})
|
125
|
+
response = RestClient::Response.create('abc', net_http_res, {:method => :put}, @request)
|
117
126
|
lambda { response.return!(@request)}.should raise_error(RestClient::MovedPermanently)
|
118
127
|
end
|
119
128
|
|
@@ -71,9 +71,9 @@ describe RestClient do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
describe 'version' do
|
74
|
-
it 'has a version ~> 1.
|
74
|
+
it 'has a version ~> 1.8.0.alpha' do
|
75
75
|
ver = Gem::Version.new(RestClient.version)
|
76
|
-
Gem::Requirement.new('~> 1.
|
76
|
+
Gem::Requirement.new('~> 1.8.0.alpha').should be_satisfied_by(ver)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
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: 1.
|
4
|
+
version: 1.8.0.rc1
|
5
5
|
platform: x86-mingw32
|
6
6
|
authors:
|
7
7
|
- REST Client Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webmock
|
@@ -86,6 +86,26 @@ dependencies:
|
|
86
86
|
- - "<"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '5.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: http-cookie
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.0.2
|
96
|
+
- - "<"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '2.0'
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 1.0.2
|
106
|
+
- - "<"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '2.0'
|
89
109
|
- !ruby/object:Gem::Dependency
|
90
110
|
name: mime-types
|
91
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -209,9 +229,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
229
|
version: 1.9.2
|
210
230
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
231
|
requirements:
|
212
|
-
- - "
|
232
|
+
- - ">"
|
213
233
|
- !ruby/object:Gem::Version
|
214
|
-
version:
|
234
|
+
version: 1.3.1
|
215
235
|
requirements: []
|
216
236
|
rubyforge_project:
|
217
237
|
rubygems_version: 2.2.2
|