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 +4 -4
- data/README.rdoc +9 -4
- data/VERSION +1 -1
- data/lib/tor/http.rb +9 -11
- data/spec/http_spec.rb +5 -3
- data/tor_requests.gemspec +1 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3039e336b9ccc9eda4c8a1c2637d701143e686ff
|
4
|
+
data.tar.gz: bc46d12b75ff059014173ae34355ff524a58f8ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b183d9288375f0570debeb7f330b936697855e895450dba8dd1f2d0930e58d85c66a58d7b568b01c67b81e3bcbaa06d03afdfb0e233c1a5ca6630f12576b6884
|
7
|
+
data.tar.gz: af016dee2a17df76220a12de563efe519dfb021fb4d3aa70e4f52bd0078ecfa033b05de228e12601c4a8e9ed7a8bbb3afe280d98d8fc95e6fca147dc0c5c0e5e
|
data/README.rdoc
CHANGED
@@ -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.
|
1
|
+
0.6.0
|
data/lib/tor/http.rb
CHANGED
@@ -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 :
|
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.
|
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.
|
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.
|
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
|
data/spec/http_spec.rb
CHANGED
@@ -17,10 +17,12 @@ describe "Http" do
|
|
17
17
|
res.code.should eq("200")
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
|
data/tor_requests.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "tor_requests"
|
8
|
-
s.version = "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.
|
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.
|
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:
|