multiplex 0.0.1 → 0.0.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 +6 -3
- data/lib/multiplex.rb +17 -17
- data/lib/multiplex/version.rb +1 -1
- data/test/multiplex_test.rb +5 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
Multiplex
|
2
2
|
=========
|
3
3
|
|
4
|
-
Multiplex
|
5
|
-
|
4
|
+
Multiplex gently monkey-patches TCPSocket to bind a Net::HTTP request to a
|
5
|
+
non-default local IP address.
|
6
|
+
|
7
|
+
If you are craving cURL's `--interface` option to fire HTTP requests over
|
8
|
+
multiple local IPs and are looking for a native Ruby solution, this is what
|
6
9
|
you need.
|
7
10
|
|
8
|
-
[
|
11
|
+

|
9
12
|
|
10
13
|
Usage
|
11
14
|
-----
|
data/lib/multiplex.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
|
3
|
+
# Multiplex gently monkey-patches TCPSocket to bind a Net::HTTP request to a
|
4
|
+
# non-default local IP address.
|
5
|
+
#
|
6
|
+
# If you are craving cURL's `interface` option, this is what you need.
|
3
7
|
module Multiplex
|
4
|
-
def bind(local_ip)
|
5
|
-
TCPSocket.instance_eval do
|
6
|
-
(class << self; self; end).instance_eval do
|
7
|
-
alias_method :original_open, :open
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
# Binds to a local IP address.
|
10
|
+
#
|
11
|
+
# If given a block, unbinds at the end of the block.
|
12
|
+
def bind(local_ip)
|
13
|
+
(class << TCPSocket; self; end).instance_eval do
|
14
|
+
alias_method :original_open, :open
|
15
|
+
define_method(:open) do |conn_address, conn_port|
|
16
|
+
original_open(conn_address, conn_port, local_ip)
|
12
17
|
end
|
13
18
|
end
|
14
19
|
|
@@ -21,18 +26,13 @@ module Multiplex
|
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
29
|
+
# Unbinds from the local IP address specified in earlier call to `bind`.
|
24
30
|
def unbind
|
25
|
-
TCPSocket.instance_eval do
|
26
|
-
|
27
|
-
|
28
|
-
remove_method :original_open
|
29
|
-
end
|
31
|
+
(class << TCPSocket; self; end).instance_eval do
|
32
|
+
alias_method :open, :original_open
|
33
|
+
remove_method :original_open
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
34
|
-
|
35
|
-
class HTTP
|
36
|
-
extend Multiplex
|
37
|
-
end
|
38
|
-
end
|
38
|
+
class Net::HTTP; extend Multiplex; end
|
data/lib/multiplex/version.rb
CHANGED
data/test/multiplex_test.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: multiplex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Paper Cavalier
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-18 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|