tor_requests 0.5.0 → 0.6.0

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: db0ac25341693bafea5996c448ef54db15aa0fde
4
- data.tar.gz: 55d973833d109be95f02a01dee6750fb98f4bb38
3
+ metadata.gz: 3039e336b9ccc9eda4c8a1c2637d701143e686ff
4
+ data.tar.gz: bc46d12b75ff059014173ae34355ff524a58f8ed
5
5
  SHA512:
6
- metadata.gz: e0d929d85ef4bcc132be60487d39e6e7125811bdea881b2f5853ede1e4fa0536722d7a90d51d7bb19fcfb3d4d7d3730600e6603669c81cb1329cc2cd3a85c08f
7
- data.tar.gz: 9defd11b28a878c01703d016de736a2efeef137360830c2c5e5f6f26a32414f50e5c426e026ce8c4fcf8c5a2a0379a82972d321fa9ff46b083c48d4d8eaedb35
6
+ metadata.gz: b183d9288375f0570debeb7f330b936697855e895450dba8dd1f2d0930e58d85c66a58d7b568b01c67b81e3bcbaa06d03afdfb0e233c1a5ca6630f12576b6884
7
+ data.tar.gz: af016dee2a17df76220a12de563efe519dfb021fb4d3aa70e4f52bd0078ecfa033b05de228e12601c4a8e9ed7a8bbb3afe280d98d8fc95e6fca147dc0c5c0e5e
@@ -22,24 +22,29 @@ with URIs (http & https)
22
22
  Tor::HTTP.get(URI('https://github.com/'))
23
23
  Tor::HTTP.post(URI('http://posttestserver.com/post.php?dir=example'), {"var" => "variable"})
24
24
 
25
-
25
+ with redirects
26
+ res = Tor::HTTP.get("google.com", "/", 80, 10)
27
+ By default 3 redirects are followed.
28
+ To prevent infinite loops a TooManyRedirects error is raised.
29
+ The limit can be changed by updating the last parameter.
30
+
26
31
  The default port configuration is 9050 and ip configuration is 127.0.0.1. If you need to change configuration, you can use:
27
32
 
28
33
  Tor.configure do |config|
29
34
  config.ip = "127.0.0.1"
30
35
  config.port = 9050
31
- end
36
+ end
32
37
 
33
38
  You can also set additional custom header fields, e.g. User-Agent:
34
39
 
35
40
  Tor.configure do |config|
36
41
  config.add_header('User-Agent', 'Netscape 2.0')
37
- end
42
+ end
38
43
 
39
44
 
40
45
 
41
46
  == Contributing to tor_requests
42
-
47
+
43
48
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
44
49
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
45
50
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
@@ -5,15 +5,14 @@ module Tor
5
5
 
6
6
  class HTTP
7
7
  class TooManyRedirects < StandardError; end
8
- REDIRECT_LIMIT = 3
9
8
 
10
9
  class << self
11
- attr_accessor :redirects_count
10
+ attr_accessor :redirects_made
12
11
  end
13
12
 
14
- def self.get(uri_or_host, path = nil, port = nil)
13
+ def self.get(uri_or_host, path = nil, port = nil, max_redirects = 3)
15
14
  res, host = "", nil
16
- self.redirects_count = 0
15
+ self.redirects_made = 0
17
16
 
18
17
  if path
19
18
  host = uri_or_host
@@ -31,8 +30,9 @@ module Tor
31
30
  end
32
31
 
33
32
  res = http.request(request)
34
- res = follow_redirect(res, http) # Follow redirects
33
+ res = follow_redirect(res, http, max_redirects) # Follow redirects
35
34
  end
35
+
36
36
  res
37
37
  end
38
38
 
@@ -76,15 +76,13 @@ module Tor
76
76
  ]
77
77
  end
78
78
 
79
- def self.follow_redirect(response, http)
79
+ def self.follow_redirect(response, http, max_redirects)
80
80
  if response.kind_of?(Net::HTTPRedirection)
81
- raise TooManyRedirects if self.redirects_count >= REDIRECT_LIMIT
82
-
81
+ raise TooManyRedirects if self.redirects_made >= max_redirects
83
82
  request = Net::HTTP::Get.new(fetch_redirect_url(response))
84
83
  response = http.request(request)
85
- self.redirects_count += 1
86
- response = follow_redirect(response, http)
87
-
84
+ self.redirects_made += 1
85
+ response = follow_redirect(response, http, max_redirects)
88
86
  else
89
87
  response
90
88
  end
@@ -17,10 +17,12 @@ describe "Http" do
17
17
  res.code.should eq("200")
18
18
  end
19
19
 
20
- it "raises TooManyRedirects error" do
21
- stub_const("Tor::HTTP::REDIRECT_LIMIT", 1)
22
- expect { Tor::HTTP.get(URI("#{protocol}://google.com/")) }.to raise_error("Tor::HTTP::TooManyRedirects")
20
+ context "with custom redirects limit" do
21
+ it "raises TooManyRedirects error after 1 retry" do
22
+ expect { Tor::HTTP.get(URI("#{protocol}://bit.ly/1ngrqeH"), nil, nil, 1) }.to raise_error("Tor::HTTP::TooManyRedirects")
23
+ end
23
24
  end
25
+
24
26
  end
25
27
  end
26
28
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "tor_requests"
8
- s.version = "0.5.0"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bruno Ghisi"]
@@ -72,4 +72,3 @@ Gem::Specification.new do |s|
72
72
  s.add_dependency(%q<socksify>, [">= 0"])
73
73
  end
74
74
  end
75
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tor_requests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Ghisi
@@ -154,8 +154,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
- rubygems_version: 2.0.3
157
+ rubygems_version: 2.0.14
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Create anonymously requests through Tor network
161
161
  test_files: []
162
+ has_rdoc: