net-http-local 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
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 => # 10.1.1.2
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
@@ -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 if defined? Net::HTTP
41
- Net::HTTPS.extend Net::HTTP::Local if defined? Net::HTTPS
42
+ Net::HTTP.extend Net::HTTP::Local
@@ -1,3 +1,3 @@
1
1
  module Net::HTTP::Local
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http-local
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: