net-http-local 0.1.1 → 0.1.2
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.
- data/README.md +3 -3
- data/lib/net/http/local.rb +3 -2
- data/lib/net/http/local/version.rb +1 -1
- data/test/net_http_local_test.rb +9 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -18,19 +18,19 @@ A contrived example:
|
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
require 'json'
|
21
|
-
require 'net/http'
|
21
|
+
require 'net/http/local'
|
22
22
|
require 'uri'
|
23
23
|
|
24
|
-
require 'net/http/local'
|
25
24
|
|
26
25
|
ip = -> do
|
27
26
|
uri = URI.parse 'http://jsonip.com'
|
28
27
|
res = Net::HTTP.get_response uri
|
28
|
+
|
29
29
|
JSON.parse(res.body)['ip']
|
30
30
|
end
|
31
31
|
|
32
32
|
# The default IP address.
|
33
|
-
p ip.call =>
|
33
|
+
p ip.call # => 10.1.1.2
|
34
34
|
|
35
35
|
# Bind to 10.1.1.3 in a block.
|
36
36
|
Net::HTTP.bind '10.1.1.3' do
|
data/lib/net/http/local.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
1
3
|
# Net::HTTP::Local binds a Net::HTTP request to a specified local address and
|
2
4
|
# port.
|
3
5
|
module Net::HTTP::Local
|
@@ -37,5 +39,4 @@ module Net::HTTP::Local
|
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
Net::HTTP.extend Net::HTTP::Local
|
41
|
-
Net::HTTPS.extend Net::HTTP::Local if defined? Net::HTTPS
|
42
|
+
Net::HTTP.extend Net::HTTP::Local
|
data/test/net_http_local_test.rb
CHANGED
@@ -2,7 +2,6 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
2
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'json'
|
5
|
-
require 'net/http'
|
6
5
|
require 'net/http/local'
|
7
6
|
|
8
7
|
class TestNetHTTPLocal < Test::Unit::TestCase
|
@@ -59,4 +58,13 @@ class TestNetHTTPLocal < Test::Unit::TestCase
|
|
59
58
|
Net::HTTP.bind nil
|
60
59
|
assert_equal @@old_ip, find_ip
|
61
60
|
end
|
61
|
+
|
62
|
+
def test_threads
|
63
|
+
thr = Thread.new do
|
64
|
+
Net::HTTP.bind @@new_ip
|
65
|
+
end
|
66
|
+
assert !TCPSocket.respond_to?(:open_with_local)
|
67
|
+
thr.join
|
68
|
+
assert TCPSocket.respond_to?(:open_with_local)
|
69
|
+
end
|
62
70
|
end
|