eventmachine-eventmachine 0.12.7 → 0.12.8

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.
Files changed (116) hide show
  1. data/{docs/README → README} +21 -13
  2. data/Rakefile +14 -4
  3. data/docs/DEFERRABLES +0 -5
  4. data/docs/INSTALL +2 -4
  5. data/docs/LEGAL +1 -1
  6. data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
  7. data/docs/PURE_RUBY +0 -2
  8. data/docs/RELEASE_NOTES +0 -2
  9. data/docs/SMTP +0 -7
  10. data/docs/SPAWNED_PROCESSES +0 -4
  11. data/docs/TODO +0 -2
  12. data/eventmachine.gemspec +17 -8
  13. data/examples/ex_channel.rb +43 -0
  14. data/examples/ex_queue.rb +2 -0
  15. data/examples/helper.rb +2 -0
  16. data/ext/cmain.cpp +119 -20
  17. data/ext/cplusplus.cpp +15 -6
  18. data/ext/ed.cpp +303 -93
  19. data/ext/ed.h +49 -22
  20. data/ext/em.cpp +368 -42
  21. data/ext/em.h +43 -6
  22. data/ext/eventmachine.h +21 -8
  23. data/ext/eventmachine_cpp.h +1 -0
  24. data/ext/extconf.rb +4 -0
  25. data/ext/kb.cpp +1 -2
  26. data/ext/pipe.cpp +1 -3
  27. data/ext/project.h +21 -0
  28. data/ext/rubymain.cpp +232 -32
  29. data/ext/ssl.cpp +38 -1
  30. data/ext/ssl.h +5 -1
  31. data/java/src/com/rubyeventmachine/Application.java +7 -3
  32. data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
  33. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
  34. data/lib/{protocols → em}/buftok.rb +16 -5
  35. data/lib/em/callback.rb +26 -0
  36. data/lib/em/channel.rb +57 -0
  37. data/lib/em/connection.rb +505 -0
  38. data/lib/em/deferrable.rb +144 -165
  39. data/lib/em/file_watch.rb +54 -0
  40. data/lib/em/future.rb +24 -25
  41. data/lib/em/messages.rb +1 -1
  42. data/lib/em/process_watch.rb +44 -0
  43. data/lib/em/processes.rb +58 -52
  44. data/lib/em/protocols/header_and_content.rb +138 -0
  45. data/lib/em/protocols/httpclient.rb +263 -0
  46. data/lib/em/protocols/httpclient2.rb +582 -0
  47. data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
  48. data/lib/em/protocols/linetext2.rb +160 -0
  49. data/lib/{protocols → em/protocols}/memcache.rb +37 -7
  50. data/lib/em/protocols/object_protocol.rb +39 -0
  51. data/lib/em/protocols/postgres3.rb +247 -0
  52. data/lib/em/protocols/saslauth.rb +175 -0
  53. data/lib/em/protocols/smtpclient.rb +331 -0
  54. data/lib/em/protocols/smtpserver.rb +547 -0
  55. data/lib/em/protocols/stomp.rb +200 -0
  56. data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
  57. data/lib/em/protocols.rb +35 -0
  58. data/lib/em/queue.rb +61 -0
  59. data/lib/em/spawnable.rb +53 -56
  60. data/lib/em/streamer.rb +92 -74
  61. data/lib/em/timers.rb +55 -0
  62. data/lib/em/version.rb +3 -0
  63. data/lib/eventmachine.rb +1008 -1298
  64. data/lib/evma.rb +1 -1
  65. data/lib/jeventmachine.rb +106 -101
  66. data/lib/pr_eventmachine.rb +47 -36
  67. data/tasks/project.rake +2 -1
  68. data/tests/client.crt +31 -0
  69. data/tests/client.key +51 -0
  70. data/tests/test_attach.rb +18 -0
  71. data/tests/test_basic.rb +108 -54
  72. data/tests/test_channel.rb +63 -0
  73. data/tests/test_connection_count.rb +2 -2
  74. data/tests/test_epoll.rb +109 -110
  75. data/tests/test_errors.rb +36 -36
  76. data/tests/test_exc.rb +22 -25
  77. data/tests/test_file_watch.rb +49 -0
  78. data/tests/test_futures.rb +77 -93
  79. data/tests/test_hc.rb +2 -2
  80. data/tests/test_httpclient.rb +55 -52
  81. data/tests/test_httpclient2.rb +110 -112
  82. data/tests/test_inactivity_timeout.rb +30 -0
  83. data/tests/test_kb.rb +8 -9
  84. data/tests/test_ltp2.rb +274 -277
  85. data/tests/test_next_tick.rb +91 -65
  86. data/tests/test_object_protocol.rb +37 -0
  87. data/tests/test_process_watch.rb +48 -0
  88. data/tests/test_processes.rb +56 -23
  89. data/tests/test_proxy_connection.rb +92 -0
  90. data/tests/test_pure.rb +1 -5
  91. data/tests/test_queue.rb +44 -0
  92. data/tests/test_running.rb +9 -14
  93. data/tests/test_sasl.rb +32 -34
  94. data/tests/test_send_file.rb +175 -176
  95. data/tests/test_servers.rb +37 -41
  96. data/tests/test_smtpserver.rb +47 -55
  97. data/tests/test_spawn.rb +284 -291
  98. data/tests/test_ssl_args.rb +1 -1
  99. data/tests/test_ssl_methods.rb +1 -1
  100. data/tests/test_ssl_verify.rb +82 -0
  101. data/tests/test_timers.rb +81 -88
  102. data/tests/test_ud.rb +0 -7
  103. data/tests/testem.rb +1 -1
  104. metadata +53 -37
  105. data/lib/em/eventable.rb +0 -39
  106. data/lib/eventmachine_version.rb +0 -31
  107. data/lib/protocols/header_and_content.rb +0 -129
  108. data/lib/protocols/httpcli2.rb +0 -803
  109. data/lib/protocols/httpclient.rb +0 -270
  110. data/lib/protocols/linetext2.rb +0 -161
  111. data/lib/protocols/postgres.rb +0 -261
  112. data/lib/protocols/saslauth.rb +0 -179
  113. data/lib/protocols/smtpclient.rb +0 -308
  114. data/lib/protocols/smtpserver.rb +0 -556
  115. data/lib/protocols/stomp.rb +0 -153
  116. data/tests/test_eventables.rb +0 -77
@@ -0,0 +1,82 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestSslVerify < Test::Unit::TestCase
6
+
7
+ def setup
8
+ $dir = File.dirname(File.expand_path(__FILE__)) + '/'
9
+ $cert_from_file = File.read($dir+'client.crt')
10
+ end
11
+
12
+ module Client
13
+ def connection_completed
14
+ start_tls(:private_key_file => $dir+'client.key', :cert_chain_file => $dir+'client.crt')
15
+ end
16
+
17
+ def ssl_handshake_completed
18
+ $client_handshake_completed = true
19
+ close_connection
20
+ end
21
+
22
+ def unbind
23
+ EM.stop_event_loop
24
+ end
25
+ end
26
+
27
+ module AcceptServer
28
+ def post_init
29
+ start_tls(:verify_peer => true)
30
+ end
31
+
32
+ def ssl_verify_peer(cert)
33
+ $cert_from_server = cert
34
+ true
35
+ end
36
+
37
+ def ssl_handshake_completed
38
+ $server_handshake_completed = true
39
+ end
40
+ end
41
+
42
+ module DenyServer
43
+ def post_init
44
+ start_tls(:verify_peer => true)
45
+ end
46
+
47
+ def ssl_verify_peer(cert)
48
+ $cert_from_server = cert
49
+ # Do not accept the peer. This should now cause the connection to shut down without the SSL handshake being completed.
50
+ false
51
+ end
52
+
53
+ def ssl_handshake_completed
54
+ $server_handshake_completed = true
55
+ end
56
+ end
57
+
58
+ def test_accept_server
59
+ $client_handshake_completed, $server_handshake_completed = false, false
60
+ EM.run {
61
+ EM.start_server("127.0.0.1", 16784, AcceptServer)
62
+ EM.connect("127.0.0.1", 16784, Client).instance_variable_get("@signature")
63
+ }
64
+
65
+ assert_equal($cert_from_file, $cert_from_server)
66
+ assert($client_handshake_completed)
67
+ assert($server_handshake_completed)
68
+ end
69
+
70
+ def test_deny_server
71
+ $client_handshake_completed, $server_handshake_completed = false, false
72
+ EM.run {
73
+ EM.start_server("127.0.0.1", 16784, DenyServer)
74
+ EM.connect("127.0.0.1", 16784, Client)
75
+ }
76
+
77
+ assert_equal($cert_from_file, $cert_from_server)
78
+ assert(!$client_handshake_completed)
79
+ assert(!$server_handshake_completed)
80
+ end
81
+
82
+ end
data/tests/test_timers.rb CHANGED
@@ -29,120 +29,113 @@ $:.unshift "../lib"
29
29
  require 'eventmachine'
30
30
  require 'test/unit'
31
31
 
32
-
33
32
  class TestTimers < Test::Unit::TestCase
34
33
 
35
- def setup
36
- end
37
-
38
- def teardown
39
- end
40
-
41
34
  def test_timer_with_block
42
- x = false
43
- EventMachine.run {
44
- EventMachine::Timer.new(0.25) {
45
- x = true
46
- EventMachine.stop
47
- }
48
- }
49
- assert x
35
+ x = false
36
+ EventMachine.run {
37
+ EventMachine::Timer.new(0.25) {
38
+ x = true
39
+ EventMachine.stop
40
+ }
41
+ }
42
+ assert x
50
43
  end
51
44
 
52
45
  def test_timer_with_proc
53
- x = false
54
- EventMachine.run {
55
- EventMachine::Timer.new(0.25, proc {
56
- x = true
57
- EventMachine.stop
58
- })
59
- }
60
- assert x
46
+ x = false
47
+ EventMachine.run {
48
+ EventMachine::Timer.new(0.25, proc {
49
+ x = true
50
+ EventMachine.stop
51
+ })
52
+ }
53
+ assert x
61
54
  end
62
55
 
63
56
  def test_timer_cancel
64
- x = true
65
- EventMachine.run {
66
- timer = EventMachine::Timer.new(0.25, proc { x = false })
67
- timer.cancel
68
- EventMachine::Timer.new(0.5, proc {EventMachine.stop})
69
- }
70
- assert x
57
+ x = true
58
+ EventMachine.run {
59
+ timer = EventMachine::Timer.new(0.25, proc { x = false })
60
+ timer.cancel
61
+ EventMachine::Timer.new(0.5, proc {EventMachine.stop})
62
+ }
63
+ assert x
71
64
  end
72
65
 
73
66
  def test_periodic_timer
74
- x = 0
75
- EventMachine.run {
76
- EventMachine::PeriodicTimer.new(0.1) do
77
- x += 1
78
- EventMachine.stop if x == 4
79
- end
80
- }
81
- assert( x == 4 )
67
+ x = 0
68
+ EventMachine.run {
69
+ EventMachine::PeriodicTimer.new(0.1) do
70
+ x += 1
71
+ EventMachine.stop if x == 4
72
+ end
73
+ }
74
+ assert( x == 4 )
82
75
  end
83
76
 
84
77
  def test_periodic_timer_cancel
85
- x = 0
86
- EventMachine.run {
87
- pt = EventMachine::PeriodicTimer.new(0.25, proc { x += 1 })
88
- pt.cancel
89
- EventMachine::Timer.new(0.5) {EventMachine.stop}
90
- }
91
- assert( x == 0 )
78
+ x = 0
79
+ EventMachine.run {
80
+ pt = EventMachine::PeriodicTimer.new(0.25, proc { x += 1 })
81
+ pt.cancel
82
+ EventMachine::Timer.new(0.5) {EventMachine.stop}
83
+ }
84
+ assert( x == 0 )
92
85
  end
93
86
 
94
87
  def test_periodic_timer_self_cancel
95
- x = 0
96
- EventMachine.run {
97
- pt = EventMachine::PeriodicTimer.new(0.1) {
98
- x += 1
99
- if x == 4
100
- pt.cancel
101
- EventMachine.stop
102
- end
103
- }
104
- }
105
- assert( x == 4 )
88
+ x = 0
89
+ EventMachine.run {
90
+ pt = EventMachine::PeriodicTimer.new(0.1) {
91
+ x += 1
92
+ if x == 4
93
+ pt.cancel
94
+ EventMachine.stop
95
+ end
96
+ }
97
+ }
98
+ assert( x == 4 )
106
99
  end
107
100
 
108
101
 
109
- # This test is only applicable to compiled versions of the reactor.
110
- # Pure ruby and java versions have no built-in limit on the number of outstanding timers.
111
- #
112
- def test_timer_change_max_outstanding
113
- ten_thousand_timers = proc {
114
- 10000.times {
115
- EM.add_timer(5) {}
116
- }
117
- }
118
- EM.run {
119
- if EM.library_type == :pure_ruby
120
- ten_thousand_timers.call
121
- elsif EM.library_type == :java
122
- ten_thousand_timers.call
123
- else
124
- begin
125
- assert_raises( RuntimeError ) {
126
- ten_thousand_timers.call
127
- }
128
- rescue Object
129
- p $!
130
- assert(false, $!.message)
131
- end
132
- end
133
- EM.stop
134
- }
102
+ # This test is only applicable to compiled versions of the reactor.
103
+ # Pure ruby and java versions have no built-in limit on the number of outstanding timers.
104
+ #
105
+ def test_timer_change_max_outstanding
106
+ ten_thousand_timers = proc {
107
+ 10000.times {
108
+ EM.add_timer(5) {}
109
+ }
110
+ }
111
+
112
+ EM.run {
113
+ if EM.library_type == :pure_ruby
114
+ ten_thousand_timers.call
115
+ elsif EM.library_type == :java
116
+ ten_thousand_timers.call
117
+ else
118
+ begin
119
+ assert_raises( RuntimeError ) {
120
+ ten_thousand_timers.call
121
+ }
122
+ rescue Object
123
+ p $!
124
+ assert(false, $!.message)
125
+ end
126
+ end
127
+ EM.stop
128
+ }
135
129
 
136
130
  assert(!EM.reactor_running?, 'Reactor running when it should not be.')
137
131
  assert( EM.get_max_timers != 10001 )
138
132
  EM.set_max_timers( 10001 )
139
133
  assert( EM.get_max_timers == 10001 )
140
134
 
141
- EM.run {
142
- ten_thousand_timers.call
143
- EM.stop
144
- }
145
- end
135
+ EM.run {
136
+ ten_thousand_timers.call
137
+ EM.stop
138
+ }
139
+ end
146
140
 
147
141
  end
148
-
data/tests/test_ud.rb CHANGED
@@ -30,14 +30,7 @@ require 'test/unit'
30
30
 
31
31
  class TestUserDefinedEvents < Test::Unit::TestCase
32
32
 
33
- def setup
34
- end
35
-
36
- def teardown
37
- end
38
-
39
33
  def test_a
40
34
  end
41
35
 
42
36
  end
43
-
data/tests/testem.rb CHANGED
@@ -28,4 +28,4 @@ end
28
28
 
29
29
  if __FILE__ == $0
30
30
  EmTestRunner.run
31
- end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventmachine-eventmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.7
4
+ version: 0.12.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Cianfrocca
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-07 00:00:00 -08:00
12
+ date: 2009-05-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,24 +20,11 @@ executables: []
20
20
  extensions:
21
21
  - ext/extconf.rb
22
22
  - ext/fastfilereader/extconf.rb
23
- extra_rdoc_files:
24
- - docs/ChangeLog
25
- - docs/COPYING
26
- - docs/DEFERRABLES
27
- - docs/EPOLL
28
- - docs/GNU
29
- - docs/INSTALL
30
- - docs/KEYBOARD
31
- - docs/LEGAL
32
- - docs/LIGHTWEIGHT_CONCURRENCY
33
- - docs/PURE_RUBY
34
- - docs/README
35
- - docs/RELEASE_NOTES
36
- - docs/SMTP
37
- - docs/SPAWNED_PROCESSES
38
- - docs/TODO
23
+ extra_rdoc_files: []
24
+
39
25
  files:
40
26
  - .gitignore
27
+ - README
41
28
  - Rakefile
42
29
  - docs/COPYING
43
30
  - docs/ChangeLog
@@ -49,12 +36,14 @@ files:
49
36
  - docs/LEGAL
50
37
  - docs/LIGHTWEIGHT_CONCURRENCY
51
38
  - docs/PURE_RUBY
52
- - docs/README
53
39
  - docs/RELEASE_NOTES
54
40
  - docs/SMTP
55
41
  - docs/SPAWNED_PROCESSES
56
42
  - docs/TODO
57
43
  - eventmachine.gemspec
44
+ - examples/ex_channel.rb
45
+ - examples/ex_queue.rb
46
+ - examples/helper.rb
58
47
  - ext/binder.cpp
59
48
  - ext/binder.h
60
49
  - ext/cmain.cpp
@@ -105,15 +94,36 @@ files:
105
94
  - java/src/com/rubyeventmachine/tests/TestDatagrams.java
106
95
  - java/src/com/rubyeventmachine/tests/TestServers.java
107
96
  - java/src/com/rubyeventmachine/tests/TestTimers.java
97
+ - lib/em/buftok.rb
98
+ - lib/em/callback.rb
99
+ - lib/em/channel.rb
100
+ - lib/em/connection.rb
108
101
  - lib/em/deferrable.rb
109
- - lib/em/eventable.rb
102
+ - lib/em/file_watch.rb
110
103
  - lib/em/future.rb
111
104
  - lib/em/messages.rb
105
+ - lib/em/process_watch.rb
112
106
  - lib/em/processes.rb
107
+ - lib/em/protocols.rb
108
+ - lib/em/protocols/header_and_content.rb
109
+ - lib/em/protocols/httpclient.rb
110
+ - lib/em/protocols/httpclient2.rb
111
+ - lib/em/protocols/line_and_text.rb
112
+ - lib/em/protocols/linetext2.rb
113
+ - lib/em/protocols/memcache.rb
114
+ - lib/em/protocols/object_protocol.rb
115
+ - lib/em/protocols/postgres3.rb
116
+ - lib/em/protocols/saslauth.rb
117
+ - lib/em/protocols/smtpclient.rb
118
+ - lib/em/protocols/smtpserver.rb
119
+ - lib/em/protocols/stomp.rb
120
+ - lib/em/protocols/tcptest.rb
121
+ - lib/em/queue.rb
113
122
  - lib/em/spawnable.rb
114
123
  - lib/em/streamer.rb
124
+ - lib/em/timers.rb
125
+ - lib/em/version.rb
115
126
  - lib/eventmachine.rb
116
- - lib/eventmachine_version.rb
117
127
  - lib/evma.rb
118
128
  - lib/evma/callback.rb
119
129
  - lib/evma/container.rb
@@ -122,43 +132,38 @@ files:
122
132
  - lib/evma/reactor.rb
123
133
  - lib/jeventmachine.rb
124
134
  - lib/pr_eventmachine.rb
125
- - lib/protocols/buftok.rb
126
- - lib/protocols/header_and_content.rb
127
- - lib/protocols/httpcli2.rb
128
- - lib/protocols/httpclient.rb
129
- - lib/protocols/line_and_text.rb
130
- - lib/protocols/linetext2.rb
131
- - lib/protocols/memcache.rb
132
- - lib/protocols/postgres.rb
133
- - lib/protocols/saslauth.rb
134
- - lib/protocols/smtpclient.rb
135
- - lib/protocols/smtpserver.rb
136
- - lib/protocols/stomp.rb
137
- - lib/protocols/tcptest.rb
138
135
  - setup.rb
139
136
  - tasks/cpp.rake
140
137
  - tasks/project.rake
141
138
  - tasks/tests.rake
139
+ - tests/client.crt
140
+ - tests/client.key
142
141
  - tests/test_attach.rb
143
142
  - tests/test_basic.rb
143
+ - tests/test_channel.rb
144
144
  - tests/test_connection_count.rb
145
145
  - tests/test_defer.rb
146
146
  - tests/test_epoll.rb
147
147
  - tests/test_error_handler.rb
148
148
  - tests/test_errors.rb
149
- - tests/test_eventables.rb
150
149
  - tests/test_exc.rb
150
+ - tests/test_file_watch.rb
151
151
  - tests/test_futures.rb
152
152
  - tests/test_handler_check.rb
153
153
  - tests/test_hc.rb
154
154
  - tests/test_httpclient.rb
155
155
  - tests/test_httpclient2.rb
156
+ - tests/test_inactivity_timeout.rb
156
157
  - tests/test_kb.rb
157
158
  - tests/test_ltp.rb
158
159
  - tests/test_ltp2.rb
159
160
  - tests/test_next_tick.rb
161
+ - tests/test_object_protocol.rb
162
+ - tests/test_process_watch.rb
160
163
  - tests/test_processes.rb
164
+ - tests/test_proxy_connection.rb
161
165
  - tests/test_pure.rb
166
+ - tests/test_queue.rb
162
167
  - tests/test_running.rb
163
168
  - tests/test_sasl.rb
164
169
  - tests/test_send_file.rb
@@ -168,6 +173,7 @@ files:
168
173
  - tests/test_spawn.rb
169
174
  - tests/test_ssl_args.rb
170
175
  - tests/test_ssl_methods.rb
176
+ - tests/test_ssl_verify.rb
171
177
  - tests/test_timers.rb
172
178
  - tests/test_ud.rb
173
179
  - tests/testem.rb
@@ -179,8 +185,18 @@ rdoc_options:
179
185
  - --title
180
186
  - EventMachine
181
187
  - --main
182
- - docs/README
188
+ - README
183
189
  - --line-numbers
190
+ - -x
191
+ - lib/em/version
192
+ - -x
193
+ - lib/emva
194
+ - -x
195
+ - lib/evma/
196
+ - -x
197
+ - lib/pr_eventmachine
198
+ - -x
199
+ - lib/jeventmachine
184
200
  require_paths:
185
201
  - lib
186
202
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -200,7 +216,7 @@ requirements: []
200
216
  rubyforge_project: eventmachine
201
217
  rubygems_version: 1.2.0
202
218
  signing_key:
203
- specification_version: 2
219
+ specification_version: 3
204
220
  summary: Ruby/EventMachine library
205
221
  test_files: []
206
222
 
data/lib/em/eventable.rb DELETED
@@ -1,39 +0,0 @@
1
- # $Id$
2
- #
3
- # Author:: Francis Cianfrocca (gmail: blackhedd)
4
- # Homepage:: http://rubyeventmachine.com
5
- # Date:: 16 Jul 2006
6
- #
7
- # See EventMachine and EventMachine::Connection for documentation and
8
- # usage examples.
9
- #
10
- #----------------------------------------------------------------------------
11
- #
12
- # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
- # Gmail: blackhedd
14
- #
15
- # This program is free software; you can redistribute it and/or modify
16
- # it under the terms of either: 1) the GNU General Public License
17
- # as published by the Free Software Foundation; either version 2 of the
18
- # License, or (at your option) any later version; or 2) Ruby's License.
19
- #
20
- # See the file COPYING for complete licensing information.
21
- #
22
- #---------------------------------------------------------------------------
23
- #
24
- #
25
-
26
-
27
- module EventMachine
28
- module Eventable
29
-
30
- def listen_event event_name
31
- end
32
-
33
- def post_event event_name, arg
34
- end
35
-
36
- end
37
- end
38
-
39
-
@@ -1,31 +0,0 @@
1
- # $Id$
2
- #
3
- # Author:: Francis Cianfrocca (gmail: blackhedd)
4
- # Homepage:: http://rubyeventmachine.com
5
- # Date:: 8 Apr 2006
6
- #
7
- # See EventMachine and EventMachine::Connection for documentation and
8
- # usage examples.
9
- #
10
- #----------------------------------------------------------------------------
11
- #
12
- # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
- # Gmail: blackhedd
14
- #
15
- # This program is free software; you can redistribute it and/or modify
16
- # it under the terms of either: 1) the GNU General Public License
17
- # as published by the Free Software Foundation; either version 2 of the
18
- # License, or (at your option) any later version; or 2) Ruby's License.
19
- #
20
- # See the file COPYING for complete licensing information.
21
- #
22
- #---------------------------------------------------------------------------
23
- #
24
- #
25
-
26
- module EventMachine
27
-
28
- VERSION = "0.12.7"
29
-
30
- end
31
-
@@ -1,129 +0,0 @@
1
- # $Id$
2
- #
3
- # Author:: Francis Cianfrocca (gmail: blackhedd)
4
- # Homepage:: http://rubyeventmachine.com
5
- # Date:: 15 Nov 2006
6
- #
7
- # See EventMachine and EventMachine::Connection for documentation and
8
- # usage examples.
9
- #
10
- #----------------------------------------------------------------------------
11
- #
12
- # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
- # Gmail: blackhedd
14
- #
15
- # This program is free software; you can redistribute it and/or modify
16
- # it under the terms of either: 1) the GNU General Public License
17
- # as published by the Free Software Foundation; either version 2 of the
18
- # License, or (at your option) any later version; or 2) Ruby's License.
19
- #
20
- # See the file COPYING for complete licensing information.
21
- #
22
- #---------------------------------------------------------------------------
23
- #
24
- #
25
-
26
-
27
-
28
- module EventMachine
29
- module Protocols
30
-
31
- # Originally, this subclassed LineAndTextProtocol, which in
32
- # turn relies on BufferedTokenizer, which doesn't gracefully
33
- # handle the transitions between lines and binary text.
34
- # Changed 13Sep08 by FCianfrocca.
35
- class HeaderAndContentProtocol < Connection
36
- include LineText2
37
-
38
-
39
- ContentLengthPattern = /Content-length:\s*(\d+)/i
40
-
41
- def initialize *args
42
- super
43
- init_for_request
44
- end
45
-
46
- def receive_line line
47
- case @hc_mode
48
- when :discard_blanks
49
- unless line == ""
50
- @hc_mode = :headers
51
- receive_line line
52
- end
53
- when :headers
54
- if line == ""
55
- raise "unrecognized state" unless @hc_headers.length > 0
56
- if respond_to?(:receive_headers)
57
- receive_headers @hc_headers
58
- end
59
- # @hc_content_length will be nil, not 0, if there was no content-length header.
60
- if @hc_content_length.to_i > 0
61
- set_binary_mode @hc_content_length
62
- else
63
- dispatch_request
64
- end
65
- else
66
- @hc_headers << line
67
- if ContentLengthPattern =~ line
68
- # There are some attacks that rely on sending multiple content-length
69
- # headers. This is a crude protection, but needs to become tunable.
70
- raise "extraneous content-length header" if @hc_content_length
71
- @hc_content_length = $1.to_i
72
- end
73
- if @hc_headers.length == 1 and respond_to?(:receive_first_header_line)
74
- receive_first_header_line line
75
- end
76
- end
77
- else
78
- raise "internal error, unsupported mode"
79
- end
80
- end
81
-
82
- def receive_binary_data text
83
- @hc_content = text
84
- dispatch_request
85
- end
86
-
87
- def dispatch_request
88
- if respond_to?(:receive_request)
89
- receive_request @hc_headers, @hc_content
90
- end
91
- init_for_request
92
- end
93
- private :dispatch_request
94
-
95
- def init_for_request
96
- @hc_mode = :discard_blanks
97
- @hc_headers = []
98
- # originally was @hc_headers ||= []; @hc_headers.clear to get a performance
99
- # boost, but it's counterproductive because a subclassed handler will have to
100
- # call dup to use the header array we pass in receive_headers.
101
-
102
- @hc_content_length = nil
103
- @hc_content = ""
104
- end
105
- private :init_for_request
106
-
107
- # Basically a convenience method. We might create a subclass that does this
108
- # automatically. But it's such a performance killer.
109
- def headers_2_hash hdrs
110
- self.class.headers_2_hash hdrs
111
- end
112
-
113
- class << self
114
- def headers_2_hash hdrs
115
- hash = {}
116
- hdrs.each {|h|
117
- if /\A([^\s:]+)\s*:\s*/ =~ h
118
- tail = $'.dup
119
- hash[ $1.downcase.gsub(/-/,"_").intern ] = tail
120
- end
121
- }
122
- hash
123
- end
124
- end
125
-
126
- end
127
- end
128
- end
129
-