eventmachine 0.12.6-java → 0.12.8-java
Sign up to get free protection for your applications and to get access to all the features.
- data/{docs/README → README} +21 -13
- data/Rakefile +5 -3
- data/docs/DEFERRABLES +0 -5
- data/docs/INSTALL +2 -4
- data/docs/LEGAL +1 -1
- data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
- data/docs/PURE_RUBY +0 -2
- data/docs/RELEASE_NOTES +0 -2
- data/docs/SMTP +0 -7
- data/docs/SPAWNED_PROCESSES +0 -4
- data/docs/TODO +0 -2
- data/eventmachine.gemspec +17 -8
- data/examples/ex_channel.rb +43 -0
- data/examples/ex_queue.rb +2 -0
- data/examples/helper.rb +2 -0
- data/ext/cmain.cpp +119 -20
- data/ext/cplusplus.cpp +15 -6
- data/ext/ed.cpp +303 -93
- data/ext/ed.h +49 -22
- data/ext/em.cpp +368 -42
- data/ext/em.h +43 -6
- data/ext/eventmachine.h +21 -8
- data/ext/eventmachine_cpp.h +1 -0
- data/ext/extconf.rb +4 -0
- data/ext/kb.cpp +1 -2
- data/ext/pipe.cpp +1 -3
- data/ext/project.h +21 -0
- data/ext/rubymain.cpp +232 -32
- data/ext/ssl.cpp +38 -1
- data/ext/ssl.h +5 -1
- data/java/src/com/rubyeventmachine/Application.java +7 -3
- data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
- data/lib/{protocols → em}/buftok.rb +16 -5
- data/lib/em/callback.rb +26 -0
- data/lib/em/channel.rb +57 -0
- data/lib/em/connection.rb +505 -0
- data/lib/em/deferrable.rb +144 -165
- data/lib/em/file_watch.rb +54 -0
- data/lib/em/future.rb +24 -25
- data/lib/em/messages.rb +1 -1
- data/lib/em/process_watch.rb +44 -0
- data/lib/em/processes.rb +58 -52
- data/lib/em/protocols.rb +35 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +263 -0
- data/lib/em/protocols/httpclient2.rb +582 -0
- data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
- data/lib/em/protocols/linetext2.rb +160 -0
- data/lib/{protocols → em/protocols}/memcache.rb +37 -7
- data/lib/em/protocols/object_protocol.rb +39 -0
- data/lib/em/protocols/postgres3.rb +247 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +331 -0
- data/lib/em/protocols/smtpserver.rb +547 -0
- data/lib/em/protocols/stomp.rb +200 -0
- data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
- data/lib/em/queue.rb +61 -0
- data/lib/em/spawnable.rb +53 -56
- data/lib/em/streamer.rb +92 -74
- data/lib/em/timers.rb +55 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1008 -1298
- data/lib/evma.rb +1 -1
- data/lib/jeventmachine.rb +106 -101
- data/lib/pr_eventmachine.rb +47 -36
- data/tasks/project.rake +2 -1
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/test_attach.rb +18 -0
- data/tests/test_basic.rb +108 -54
- data/tests/test_channel.rb +63 -0
- data/tests/test_connection_count.rb +2 -2
- data/tests/test_epoll.rb +109 -110
- data/tests/test_errors.rb +36 -36
- data/tests/test_exc.rb +22 -25
- data/tests/test_file_watch.rb +49 -0
- data/tests/test_futures.rb +77 -93
- data/tests/test_hc.rb +2 -2
- data/tests/test_httpclient.rb +55 -52
- data/tests/test_httpclient2.rb +110 -112
- data/tests/test_inactivity_timeout.rb +30 -0
- data/tests/test_kb.rb +8 -9
- data/tests/test_ltp2.rb +274 -277
- data/tests/test_next_tick.rb +91 -65
- data/tests/test_object_protocol.rb +37 -0
- data/tests/test_process_watch.rb +48 -0
- data/tests/test_processes.rb +56 -23
- data/tests/test_proxy_connection.rb +92 -0
- data/tests/test_pure.rb +1 -5
- data/tests/test_queue.rb +44 -0
- data/tests/test_running.rb +9 -14
- data/tests/test_sasl.rb +32 -34
- data/tests/test_send_file.rb +175 -176
- data/tests/test_servers.rb +37 -41
- data/tests/test_smtpserver.rb +47 -55
- data/tests/test_spawn.rb +284 -291
- data/tests/test_ssl_args.rb +1 -1
- data/tests/test_ssl_methods.rb +1 -1
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_timers.rb +81 -88
- data/tests/test_ud.rb +0 -7
- data/tests/testem.rb +1 -1
- metadata +52 -36
- data/lib/em/eventable.rb +0 -39
- data/lib/eventmachine_version.rb +0 -31
- data/lib/protocols/header_and_content.rb +0 -129
- data/lib/protocols/httpcli2.rb +0 -803
- data/lib/protocols/httpclient.rb +0 -270
- data/lib/protocols/linetext2.rb +0 -161
- data/lib/protocols/postgres.rb +0 -261
- data/lib/protocols/saslauth.rb +0 -179
- data/lib/protocols/smtpclient.rb +0 -308
- data/lib/protocols/smtpserver.rb +0 -556
- data/lib/protocols/stomp.rb +0 -153
- data/tests/test_eventables.rb +0 -77
data/tests/test_errors.rb
CHANGED
@@ -36,47 +36,47 @@ require 'test/unit'
|
|
36
36
|
|
37
37
|
class TestErrors < Test::Unit::TestCase
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
Localhost = "127.0.0.1"
|
40
|
+
Localport = 9801
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
def setup
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
def obsolete_teardown
|
46
|
+
# Calling #set_runtime_error_hook with no block restores the
|
47
|
+
# default handling of runtime_errors.
|
48
|
+
#
|
49
|
+
EM.set_runtime_error_hook
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
def test_no_tests_stub
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
55
|
+
# EM has a default handler for RuntimeErrors that are emitted from
|
56
|
+
# user written code. You can override the handler if you wish, but it's
|
57
|
+
# easier to call #set_runtime_error_hook.
|
58
|
+
# Ordinarily, an error in user code invoked by the reactor aborts the
|
59
|
+
# run.
|
60
|
+
#
|
61
|
+
def obsolete_test_unhandled_error
|
62
|
+
assert_raises( RuntimeError ) {
|
63
|
+
EM.run {
|
64
|
+
EM.add_timer(0) {raise "AAA"}
|
65
|
+
}
|
66
|
+
}
|
67
67
|
|
68
|
-
|
68
|
+
end
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
70
|
+
def obsolete_test_handled_error
|
71
|
+
err = nil
|
72
|
+
EM.run {
|
73
|
+
EM.set_runtime_error_hook {
|
74
|
+
err = true
|
75
|
+
EM.stop
|
76
|
+
}
|
77
|
+
EM.add_timer(0) {raise "AAA"}
|
78
|
+
}
|
79
|
+
assert err
|
80
|
+
end
|
81
81
|
end
|
82
82
|
|
data/tests/test_exc.rb
CHANGED
@@ -29,30 +29,27 @@ require 'test/unit'
|
|
29
29
|
|
30
30
|
class TestSomeExceptions < Test::Unit::TestCase
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
|
32
|
+
# Read the commentary in EventMachine#run.
|
33
|
+
# This test exercises the ensure block in #run that makes sure
|
34
|
+
# EventMachine#release_machine gets called even if an exception is
|
35
|
+
# thrown within the user code. Without the ensured call to release_machine,
|
36
|
+
# the second call to EventMachine#run will fail with a C++ exception
|
37
|
+
# because the machine wasn't cleaned up properly.
|
38
|
+
|
39
|
+
def test_a
|
40
|
+
assert_raises(RuntimeError) {
|
41
|
+
EventMachine.run {
|
42
|
+
raise "some exception"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_b
|
48
|
+
assert_raises(RuntimeError) {
|
49
|
+
EventMachine.run {
|
50
|
+
raise "some exception"
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
56
54
|
|
57
55
|
end
|
58
|
-
|
@@ -0,0 +1,49 @@
|
|
1
|
+
$:.unshift "../lib"
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestFileWatch < Test::Unit::TestCase
|
6
|
+
module FileWatcher
|
7
|
+
def file_modified
|
8
|
+
$modified = true
|
9
|
+
end
|
10
|
+
def file_deleted
|
11
|
+
$deleted = true
|
12
|
+
end
|
13
|
+
def unbind
|
14
|
+
$unbind = true
|
15
|
+
EM.stop
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
EM.kqueue = true if EM.kqueue?
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
EM.kqueue = false if EM.kqueue?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_events
|
28
|
+
EM.run{
|
29
|
+
require 'tempfile'
|
30
|
+
file = Tempfile.new('em-watch')
|
31
|
+
$tmp_path = file.path
|
32
|
+
|
33
|
+
# watch it
|
34
|
+
watch = EM.watch_file(file.path, FileWatcher)
|
35
|
+
$path = watch.path
|
36
|
+
|
37
|
+
# modify it
|
38
|
+
File.open(file.path, 'w'){ |f| f.puts 'hi' }
|
39
|
+
|
40
|
+
# delete it
|
41
|
+
EM.add_timer(0.25){ file.close; file.delete }
|
42
|
+
}
|
43
|
+
|
44
|
+
assert_equal($path, $tmp_path)
|
45
|
+
assert($modified)
|
46
|
+
assert($deleted)
|
47
|
+
assert($unbind)
|
48
|
+
end
|
49
|
+
end
|
data/tests/test_futures.rb
CHANGED
@@ -28,8 +28,6 @@ $:.unshift "../lib"
|
|
28
28
|
require 'eventmachine'
|
29
29
|
require 'test/unit'
|
30
30
|
|
31
|
-
|
32
|
-
|
33
31
|
class TestFutures < Test::Unit::TestCase
|
34
32
|
|
35
33
|
def setup
|
@@ -45,21 +43,19 @@ class TestFutures < Test::Unit::TestCase
|
|
45
43
|
assert_equal(101, EventMachine::Deferrable.future(p1) )
|
46
44
|
end
|
47
45
|
|
48
|
-
|
49
|
-
|
50
46
|
class MyFuture
|
51
47
|
include EventMachine::Deferrable
|
52
48
|
def initialize *args
|
53
|
-
|
54
|
-
|
49
|
+
super
|
50
|
+
set_deferred_status :succeeded, 40
|
55
51
|
end
|
56
52
|
end
|
57
53
|
|
58
54
|
class MyErrorFuture
|
59
55
|
include EventMachine::Deferrable
|
60
56
|
def initialize *args
|
61
|
-
|
62
|
-
|
57
|
+
super
|
58
|
+
set_deferred_status :failed, 41
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
@@ -67,7 +63,7 @@ class TestFutures < Test::Unit::TestCase
|
|
67
63
|
def test_future_1
|
68
64
|
# Call future with one additional argument and it will be treated as a callback.
|
69
65
|
def my_future
|
70
|
-
|
66
|
+
MyFuture.new
|
71
67
|
end
|
72
68
|
|
73
69
|
value = nil
|
@@ -90,7 +86,7 @@ class TestFutures < Test::Unit::TestCase
|
|
90
86
|
# treated as a callback.
|
91
87
|
value = nil
|
92
88
|
EventMachine::Deferrable.future MyFuture.new do |v|
|
93
|
-
|
89
|
+
value=v
|
94
90
|
end
|
95
91
|
assert_equal( 40, value )
|
96
92
|
end
|
@@ -107,108 +103,96 @@ class TestFutures < Test::Unit::TestCase
|
|
107
103
|
n = 0 # counter assures that all the tests actually run.
|
108
104
|
rc = RecursiveCallback.new
|
109
105
|
rc.callback {|a|
|
110
|
-
|
111
|
-
|
112
|
-
|
106
|
+
assert_equal(100, a)
|
107
|
+
n += 1
|
108
|
+
rc.set_deferred_status :succeeded, 101, 101
|
113
109
|
}
|
114
110
|
rc.callback {|a,b|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
111
|
+
assert_equal(101, a)
|
112
|
+
assert_equal(101, b)
|
113
|
+
n += 1
|
114
|
+
rc.set_deferred_status :succeeded, 102, 102, 102
|
119
115
|
}
|
120
116
|
rc.callback {|a,b,c|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
117
|
+
assert_equal(102, a)
|
118
|
+
assert_equal(102, b)
|
119
|
+
assert_equal(102, c)
|
120
|
+
n += 1
|
125
121
|
}
|
126
122
|
rc.set_deferred_status :succeeded, 100
|
127
123
|
assert_equal(3, n)
|
128
124
|
end
|
129
125
|
|
126
|
+
def test_syntactic_sugar
|
127
|
+
rc = RecursiveCallback.new
|
128
|
+
rc.set_deferred_success 100
|
129
|
+
rc.set_deferred_failure 200
|
130
|
+
end
|
130
131
|
|
132
|
+
# It doesn't raise an error to set deferred status more than once.
|
133
|
+
# In fact, this is a desired and useful idiom when it happens INSIDE
|
134
|
+
# a callback or errback.
|
135
|
+
# However, it's less useful otherwise, and in fact would generally be
|
136
|
+
# indicative of a programming error. However, we would like to be resistant
|
137
|
+
# to such errors. So whenever we set deferred status, we also clear BOTH
|
138
|
+
# stacks of handlers.
|
139
|
+
#
|
140
|
+
def test_double_calls
|
141
|
+
s = 0
|
142
|
+
e = 0
|
131
143
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
rc.set_deferred_failure 200
|
136
|
-
end
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
# It doesn't raise an error to set deferred status more than once.
|
141
|
-
# In fact, this is a desired and useful idiom when it happens INSIDE
|
142
|
-
# a callback or errback.
|
143
|
-
# However, it's less useful otherwise, and in fact would generally be
|
144
|
-
# indicative of a programming error. However, we would like to be resistant
|
145
|
-
# to such errors. So whenever we set deferred status, we also clear BOTH
|
146
|
-
# stacks of handlers.
|
147
|
-
#
|
148
|
-
def test_double_calls
|
149
|
-
s = 0
|
150
|
-
e = 0
|
151
|
-
|
152
|
-
d = EM::DefaultDeferrable.new
|
153
|
-
d.callback {s += 1}
|
154
|
-
d.errback {e += 1}
|
155
|
-
|
156
|
-
d.succeed # We expect the callback to be called, and the errback to be DISCARDED.
|
157
|
-
d.fail # Presumably an error. We expect the errback NOT to be called.
|
158
|
-
d.succeed # We expect the callback to have been discarded and NOT to be called again.
|
159
|
-
|
160
|
-
assert_equal(1, s)
|
161
|
-
assert_equal(0, e)
|
162
|
-
end
|
163
|
-
|
164
|
-
|
165
|
-
# Adding a callback to a Deferrable that is already in a success state executes the callback
|
166
|
-
# immediately. The same applies to a an errback added to an already-failed Deferrable.
|
167
|
-
# HOWEVER, we expect NOT to be able to add errbacks to succeeded Deferrables, or callbacks
|
168
|
-
# to failed ones.
|
169
|
-
#
|
170
|
-
# We illustrate this with a rather contrived test. The test calls #fail after #succeed,
|
171
|
-
# which ordinarily would not happen in a real program.
|
172
|
-
#
|
173
|
-
# What we're NOT attempting to specify is what happens if a Deferrable is succeeded and then
|
174
|
-
# failed (or vice-versa). Should we then be able to add callbacks/errbacks of the appropriate
|
175
|
-
# type for immediate execution? For now at least, the official answer is "don't do that."
|
176
|
-
#
|
177
|
-
def test_delayed_callbacks
|
178
|
-
s1 = 0
|
179
|
-
s2 = 0
|
180
|
-
e = 0
|
144
|
+
d = EM::DefaultDeferrable.new
|
145
|
+
d.callback {s += 1}
|
146
|
+
d.errback {e += 1}
|
181
147
|
|
182
|
-
|
183
|
-
|
148
|
+
d.succeed # We expect the callback to be called, and the errback to be DISCARDED.
|
149
|
+
d.fail # Presumably an error. We expect the errback NOT to be called.
|
150
|
+
d.succeed # We expect the callback to have been discarded and NOT to be called again.
|
184
151
|
|
185
|
-
|
152
|
+
assert_equal(1, s)
|
153
|
+
assert_equal(0, e)
|
154
|
+
end
|
186
155
|
|
187
|
-
|
156
|
+
# Adding a callback to a Deferrable that is already in a success state executes the callback
|
157
|
+
# immediately. The same applies to a an errback added to an already-failed Deferrable.
|
158
|
+
# HOWEVER, we expect NOT to be able to add errbacks to succeeded Deferrables, or callbacks
|
159
|
+
# to failed ones.
|
160
|
+
#
|
161
|
+
# We illustrate this with a rather contrived test. The test calls #fail after #succeed,
|
162
|
+
# which ordinarily would not happen in a real program.
|
163
|
+
#
|
164
|
+
# What we're NOT attempting to specify is what happens if a Deferrable is succeeded and then
|
165
|
+
# failed (or vice-versa). Should we then be able to add callbacks/errbacks of the appropriate
|
166
|
+
# type for immediate execution? For now at least, the official answer is "don't do that."
|
167
|
+
#
|
168
|
+
def test_delayed_callbacks
|
169
|
+
s1 = 0
|
170
|
+
s2 = 0
|
171
|
+
e = 0
|
188
172
|
|
189
|
-
|
190
|
-
|
173
|
+
d = EM::DefaultDeferrable.new
|
174
|
+
d.callback {s1 += 1}
|
191
175
|
|
192
|
-
|
193
|
-
assert_equal( 0, e )
|
194
|
-
end
|
176
|
+
d.succeed # Triggers and discards the callback.
|
195
177
|
|
178
|
+
d.callback {s2 += 1} # This callback is executed immediately and discarded.
|
196
179
|
|
180
|
+
d.errback {e += 1} # This errback should be DISCARDED and never execute.
|
181
|
+
d.fail # To prove it, fail and assert e is 0
|
197
182
|
|
183
|
+
assert_equal( [1,1], [s1,s2] )
|
184
|
+
assert_equal( 0, e )
|
185
|
+
end
|
198
186
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
}
|
210
|
-
assert_equal( 2, n )
|
211
|
-
end
|
187
|
+
def test_timeout
|
188
|
+
n = 0
|
189
|
+
EM.run {
|
190
|
+
d = EM::DefaultDeferrable.new
|
191
|
+
d.callback {n = 1; EM.stop}
|
192
|
+
d.errback {n = 2; EM.stop}
|
193
|
+
d.timeout(1)
|
194
|
+
}
|
195
|
+
assert_equal( 2, n )
|
196
|
+
end
|
212
197
|
|
213
198
|
end
|
214
|
-
|
data/tests/test_hc.rb
CHANGED
@@ -176,7 +176,7 @@ class TestHeaderAndContentProtocol < Test::Unit::TestCase
|
|
176
176
|
"GET / HTTP/1.0",
|
177
177
|
"Accept: aaa",
|
178
178
|
"User-Agent: bbb",
|
179
|
-
"Host:
|
179
|
+
"Host: ccc",
|
180
180
|
"x-tempest-header:ddd"
|
181
181
|
]
|
182
182
|
|
@@ -215,4 +215,4 @@ class TestHeaderAndContentProtocol < Test::Unit::TestCase
|
|
215
215
|
assert_equal(expect, hsh)
|
216
216
|
end
|
217
217
|
|
218
|
-
end
|
218
|
+
end
|
data/tests/test_httpclient.rb
CHANGED
@@ -91,23 +91,23 @@ class TestHttpClient < Test::Unit::TestCase
|
|
91
91
|
#
|
92
92
|
class EmptyContent < EventMachine::Connection
|
93
93
|
def initialize *args
|
94
|
-
|
94
|
+
super
|
95
95
|
end
|
96
96
|
def receive_data data
|
97
|
-
|
98
|
-
|
97
|
+
send_data "HTTP/1.0 404 ...\r\nContent-length: 0\r\n\r\n"
|
98
|
+
close_connection_after_writing
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
def test_http_empty_content
|
103
103
|
ok = false
|
104
104
|
EventMachine.run {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
105
|
+
EventMachine.start_server "127.0.0.1", 9701, EmptyContent
|
106
|
+
c = EventMachine::Protocols::HttpClient.send :request, :host => "127.0.0.1", :port => 9701
|
107
|
+
c.callback {|result|
|
108
|
+
ok = true
|
109
|
+
EventMachine.stop
|
110
|
+
}
|
111
111
|
}
|
112
112
|
assert ok
|
113
113
|
end
|
@@ -117,40 +117,41 @@ class TestHttpClient < Test::Unit::TestCase
|
|
117
117
|
|
118
118
|
class PostContent < EventMachine::Protocols::LineAndTextProtocol
|
119
119
|
def initialize *args
|
120
|
-
|
121
|
-
|
120
|
+
super
|
121
|
+
@lines = []
|
122
122
|
end
|
123
123
|
def receive_line line
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
124
|
+
if line.length > 0
|
125
|
+
@lines << line
|
126
|
+
else
|
127
|
+
process_headers
|
128
|
+
end
|
129
129
|
end
|
130
130
|
def receive_binary_data data
|
131
|
-
|
132
|
-
|
131
|
+
@post_content = data
|
132
|
+
send_response
|
133
133
|
end
|
134
134
|
def process_headers
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
135
|
+
if @lines.first =~ /\APOST ([^\s]+) HTTP\/1.1\Z/
|
136
|
+
@uri = $1.dup
|
137
|
+
else
|
138
|
+
raise "bad request"
|
139
|
+
end
|
140
|
+
|
141
|
+
@lines.each {|line|
|
142
|
+
if line =~ /\AContent-length:\s*(\d+)\Z/i
|
143
|
+
@content_length = $1.dup.to_i
|
144
|
+
elsif line =~ /\AContent-type:\s*(\d+)\Z/i
|
145
|
+
@content_type = $1.dup
|
146
|
+
end
|
147
|
+
}
|
148
|
+
|
149
|
+
raise "invalid content length" unless @content_length
|
150
|
+
set_binary_mode @content_length
|
150
151
|
end
|
151
152
|
def send_response
|
152
|
-
|
153
|
-
|
153
|
+
send_data "HTTP/1.1 200 ...\r\nConnection: close\r\nContent-length: 10\r\nContent-type: text/html\r\n\r\n0123456789"
|
154
|
+
close_connection_after_writing
|
154
155
|
end
|
155
156
|
end
|
156
157
|
|
@@ -159,15 +160,20 @@ class TestHttpClient < Test::Unit::TestCase
|
|
159
160
|
def test_post
|
160
161
|
response = nil
|
161
162
|
EventMachine.run {
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
163
|
+
EventMachine.start_server Localhost, Localport, PostContent
|
164
|
+
EventMachine.add_timer(2) {raise "timed out"}
|
165
|
+
c = EventMachine::Protocols::HttpClient.request(
|
166
|
+
:host=>Localhost,
|
167
|
+
:port=>Localport,
|
168
|
+
:method=>:post,
|
169
|
+
:request=>"/aaa",
|
170
|
+
:content=>"XYZ",
|
171
|
+
:content_type=>"text/plain"
|
172
|
+
)
|
173
|
+
c.callback {|r|
|
174
|
+
response = r
|
175
|
+
EventMachine.stop
|
176
|
+
}
|
171
177
|
}
|
172
178
|
|
173
179
|
assert_equal( 200, response[:status] )
|
@@ -190,16 +196,16 @@ class TestHttpClient < Test::Unit::TestCase
|
|
190
196
|
assert ok
|
191
197
|
end
|
192
198
|
|
193
|
-
|
194
|
-
|
195
199
|
# We can tell the client to send an HTTP/1.0 request (default is 1.1).
|
196
200
|
# This is useful for suppressing chunked responses until those are working.
|
197
201
|
def test_version_1_0
|
198
202
|
ok = false
|
199
203
|
EM.run {
|
200
|
-
c = EM::P::HttpClient.request
|
201
|
-
|
202
|
-
|
204
|
+
c = EM::P::HttpClient.request(
|
205
|
+
:host => "www.bayshorenetworks.com",
|
206
|
+
:port => 80,
|
207
|
+
:version => "1.0"
|
208
|
+
)
|
203
209
|
c.callback {|result|
|
204
210
|
ok = true;
|
205
211
|
EventMachine.stop
|
@@ -209,7 +215,4 @@ class TestHttpClient < Test::Unit::TestCase
|
|
209
215
|
assert ok
|
210
216
|
end
|
211
217
|
|
212
|
-
|
213
218
|
end
|
214
|
-
|
215
|
-
|