eventmachine_httpserver 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,26 @@
1
- # $Id: response.rb 3893 2007-03-06 20:12:09Z francis $
2
- #
3
- #
4
-
5
-
6
- $:.unshift(File.dirname(__FILE__) + '/../lib')
7
-
8
- require 'eventmachine'
1
+ require 'test/unit'
9
2
  require 'evma_httpserver'
10
3
 
4
+ begin
5
+ once = false
6
+ require 'eventmachine'
7
+ rescue LoadError => e
8
+ raise e if once
9
+ once = true
10
+ require 'rubygems'
11
+ retry
12
+ end
13
+
11
14
 
12
15
  #--------------------------------------
13
16
 
14
- module EventMachine
15
17
 
16
- # This is a test harness wired into the HttpResponse class so we
17
- # can test it without requiring any actual network communication.
18
+ class TestDelegatedHttpResponse < Test::Unit::TestCase
19
+
20
+ # This is a delegate class that (trivially) implements the
21
+ # several classes needed to work with HttpResponse.
18
22
  #
19
- class HttpResponse
23
+ class D
20
24
  attr_reader :output_data
21
25
  attr_reader :closed_after_writing
22
26
 
@@ -28,12 +32,6 @@ module EventMachine
28
32
  @closed_after_writing = true
29
33
  end
30
34
  end
31
- end
32
-
33
- #--------------------------------------
34
-
35
-
36
- class TestHttpResponse < Test::Unit::TestCase
37
35
 
38
36
  def setup
39
37
  end
@@ -44,14 +42,14 @@ class TestHttpResponse < Test::Unit::TestCase
44
42
 
45
43
 
46
44
  def test_properties
47
- a = EventMachine::HttpResponse.new
45
+ a = EM::DelegatedHttpResponse.new( D.new )
48
46
  a.status = 200
49
47
  a.content = "Some content"
50
48
  a.headers["Content-type"] = "text/xml"
51
49
  end
52
50
 
53
51
  def test_header_sugarings
54
- a = EventMachine::HttpResponse.new
52
+ a = EM::DelegatedHttpResponse.new( D.new )
55
53
  a.content_type "text/xml"
56
54
  a.set_cookie "a=b"
57
55
  a.headers["X-bayshore"] = "aaaa"
@@ -64,19 +62,21 @@ class TestHttpResponse < Test::Unit::TestCase
64
62
  end
65
63
 
66
64
  def test_send_response
67
- a = EventMachine::HttpResponse.new
65
+ d = D.new
66
+ a = EM::DelegatedHttpResponse.new( d )
68
67
  a.status = 200
69
68
  a.send_response
70
69
  assert_equal([
71
70
  "HTTP/1.1 200 ...\r\n",
72
71
  "Content-length: 0\r\n",
73
72
  "\r\n"
74
- ].join, a.output_data)
75
- assert_equal( true, a.closed_after_writing )
73
+ ].join, d.output_data)
74
+ assert_equal( true, d.closed_after_writing )
76
75
  end
77
76
 
78
77
  def test_send_response_1
79
- a = EventMachine::HttpResponse.new
78
+ d = D.new
79
+ a = EM::DelegatedHttpResponse.new( d )
80
80
  a.status = 200
81
81
  a.content_type "text/plain"
82
82
  a.content = "ABC"
@@ -87,12 +87,13 @@ class TestHttpResponse < Test::Unit::TestCase
87
87
  "Content-type: text/plain\r\n",
88
88
  "\r\n",
89
89
  "ABC"
90
- ].join, a.output_data)
91
- assert( a.closed_after_writing )
90
+ ].join, d.output_data)
91
+ assert( d.closed_after_writing )
92
92
  end
93
93
 
94
94
  def test_send_response_no_close
95
- a = EventMachine::HttpResponse.new
95
+ d = D.new
96
+ a = EM::DelegatedHttpResponse.new( d )
96
97
  a.status = 200
97
98
  a.content_type "text/plain"
98
99
  a.content = "ABC"
@@ -104,12 +105,12 @@ class TestHttpResponse < Test::Unit::TestCase
104
105
  "Content-type: text/plain\r\n",
105
106
  "\r\n",
106
107
  "ABC"
107
- ].join, a.output_data)
108
- assert( ! a.closed_after_writing )
108
+ ].join, d.output_data)
109
+ assert( ! d.closed_after_writing )
109
110
  end
110
111
 
111
112
  def test_send_response_multiple_times
112
- a = EventMachine::HttpResponse.new
113
+ a = EM::DelegatedHttpResponse.new( D.new )
113
114
  a.status = 200
114
115
  a.send_response
115
116
  assert_raise( RuntimeError ) {
@@ -118,22 +119,24 @@ class TestHttpResponse < Test::Unit::TestCase
118
119
  end
119
120
 
120
121
  def test_send_headers
121
- a = EventMachine::HttpResponse.new
122
+ d = D.new
123
+ a = EM::DelegatedHttpResponse.new( d )
122
124
  a.status = 200
123
125
  a.send_headers
124
126
  assert_equal([
125
127
  "HTTP/1.1 200 ...\r\n",
126
128
  "Content-length: 0\r\n",
127
129
  "\r\n"
128
- ].join, a.output_data)
129
- assert( ! a.closed_after_writing )
130
+ ].join, d.output_data)
131
+ assert( ! d.closed_after_writing )
130
132
  assert_raise( RuntimeError ) {
131
133
  a.send_headers
132
134
  }
133
135
  end
134
136
 
135
137
  def test_send_chunks
136
- a = EventMachine::HttpResponse.new
138
+ d = D.new
139
+ a = EM::DelegatedHttpResponse.new( d )
137
140
  a.chunk "ABC"
138
141
  a.chunk "DEF"
139
142
  a.chunk "GHI"
@@ -151,12 +154,13 @@ class TestHttpResponse < Test::Unit::TestCase
151
154
  "GHI\r\n",
152
155
  "0\r\n",
153
156
  "\r\n"
154
- ].join, a.output_data)
155
- assert( !a.closed_after_writing )
157
+ ].join, d.output_data)
158
+ assert( !d.closed_after_writing )
156
159
  end
157
160
 
158
161
  def test_send_chunks_with_close
159
- a = EventMachine::HttpResponse.new
162
+ d = D.new
163
+ a = EM::DelegatedHttpResponse.new( d )
160
164
  a.chunk "ABC"
161
165
  a.chunk "DEF"
162
166
  a.chunk "GHI"
@@ -173,8 +177,8 @@ class TestHttpResponse < Test::Unit::TestCase
173
177
  "GHI\r\n",
174
178
  "0\r\n",
175
179
  "\r\n"
176
- ].join, a.output_data)
177
- assert( a.closed_after_writing )
180
+ ].join, d.output_data)
181
+ assert( d.closed_after_writing )
178
182
  end
179
183
 
180
184
  end
@@ -0,0 +1,178 @@
1
+ require 'test/unit'
2
+ require 'evma_httpserver'
3
+
4
+ begin
5
+ once = false
6
+ require 'eventmachine'
7
+ rescue LoadError => e
8
+ raise e if once
9
+ once = true
10
+ require 'rubygems'
11
+ retry
12
+ end
13
+
14
+
15
+ #--------------------------------------
16
+
17
+ module EventMachine
18
+
19
+ # This is a test harness wired into the HttpResponse class so we
20
+ # can test it without requiring any actual network communication.
21
+ #
22
+ class HttpResponse
23
+ attr_reader :output_data
24
+ attr_reader :closed_after_writing
25
+
26
+ def send_data data
27
+ @output_data ||= ""
28
+ @output_data << data
29
+ end
30
+ def close_connection_after_writing
31
+ @closed_after_writing = true
32
+ end
33
+ end
34
+ end
35
+
36
+ #--------------------------------------
37
+
38
+
39
+ class TestHttpResponse < Test::Unit::TestCase
40
+
41
+ def test_properties
42
+ a = EventMachine::HttpResponse.new
43
+ a.status = 200
44
+ a.content = "Some content"
45
+ a.headers["Content-type"] = "text/xml"
46
+ end
47
+
48
+ def test_header_sugarings
49
+ a = EventMachine::HttpResponse.new
50
+ a.content_type "text/xml"
51
+ a.set_cookie "a=b"
52
+ a.headers["X-bayshore"] = "aaaa"
53
+
54
+ assert_equal({
55
+ "Content-type" => "text/xml",
56
+ "Set-cookie" => ["a=b"],
57
+ "X-bayshore" => "aaaa"
58
+ }, a.headers)
59
+ end
60
+
61
+ def test_send_response
62
+ a = EventMachine::HttpResponse.new
63
+ a.status = 200
64
+ a.send_response
65
+ assert_equal([
66
+ "HTTP/1.1 200 ...\r\n",
67
+ "Content-length: 0\r\n",
68
+ "\r\n"
69
+ ].join, a.output_data)
70
+ assert_equal( true, a.closed_after_writing )
71
+ end
72
+
73
+ def test_send_response_1
74
+ a = EventMachine::HttpResponse.new
75
+ a.status = 200
76
+ a.content_type "text/plain"
77
+ a.content = "ABC"
78
+ a.send_response
79
+ assert_equal([
80
+ "HTTP/1.1 200 ...\r\n",
81
+ "Content-length: 3\r\n",
82
+ "Content-type: text/plain\r\n",
83
+ "\r\n",
84
+ "ABC"
85
+ ].join, a.output_data)
86
+ assert( a.closed_after_writing )
87
+ end
88
+
89
+ def test_send_response_no_close
90
+ a = EventMachine::HttpResponse.new
91
+ a.status = 200
92
+ a.content_type "text/plain"
93
+ a.content = "ABC"
94
+ a.keep_connection_open
95
+ a.send_response
96
+ assert_equal([
97
+ "HTTP/1.1 200 ...\r\n",
98
+ "Content-length: 3\r\n",
99
+ "Content-type: text/plain\r\n",
100
+ "\r\n",
101
+ "ABC"
102
+ ].join, a.output_data)
103
+ assert( ! a.closed_after_writing )
104
+ end
105
+
106
+ def test_send_response_multiple_times
107
+ a = EventMachine::HttpResponse.new
108
+ a.status = 200
109
+ a.send_response
110
+ assert_raise( RuntimeError ) {
111
+ a.send_response
112
+ }
113
+ end
114
+
115
+ def test_send_headers
116
+ a = EventMachine::HttpResponse.new
117
+ a.status = 200
118
+ a.send_headers
119
+ assert_equal([
120
+ "HTTP/1.1 200 ...\r\n",
121
+ "Content-length: 0\r\n",
122
+ "\r\n"
123
+ ].join, a.output_data)
124
+ assert( ! a.closed_after_writing )
125
+ assert_raise( RuntimeError ) {
126
+ a.send_headers
127
+ }
128
+ end
129
+
130
+ def test_send_chunks
131
+ a = EventMachine::HttpResponse.new
132
+ a.chunk "ABC"
133
+ a.chunk "DEF"
134
+ a.chunk "GHI"
135
+ a.keep_connection_open
136
+ a.send_response
137
+ assert_equal([
138
+ "HTTP/1.1 200 ...\r\n",
139
+ "Transfer-encoding: chunked\r\n",
140
+ "\r\n",
141
+ "3\r\n",
142
+ "ABC\r\n",
143
+ "3\r\n",
144
+ "DEF\r\n",
145
+ "3\r\n",
146
+ "GHI\r\n",
147
+ "0\r\n",
148
+ "\r\n"
149
+ ].join, a.output_data)
150
+ assert( !a.closed_after_writing )
151
+ end
152
+
153
+ def test_send_chunks_with_close
154
+ a = EventMachine::HttpResponse.new
155
+ a.chunk "ABC"
156
+ a.chunk "DEF"
157
+ a.chunk "GHI"
158
+ a.send_response
159
+ assert_equal([
160
+ "HTTP/1.1 200 ...\r\n",
161
+ "Transfer-encoding: chunked\r\n",
162
+ "\r\n",
163
+ "3\r\n",
164
+ "ABC\r\n",
165
+ "3\r\n",
166
+ "DEF\r\n",
167
+ "3\r\n",
168
+ "GHI\r\n",
169
+ "0\r\n",
170
+ "\r\n"
171
+ ].join, a.output_data)
172
+ assert( a.closed_after_writing )
173
+ end
174
+
175
+ end
176
+
177
+
178
+
metadata CHANGED
@@ -1,66 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: eventmachine_httpserver
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-03-16 00:00:00 -04:00
8
- summary: EventMachine HTTP Server
9
- require_paths:
10
- - lib
11
- email: garbagecat10@gmail.com
12
- homepage: http://www.eventmachine.com
13
- rubyforge_project:
14
- description: ""
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.1.1
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Francis Cianfrocca
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ date: 2007-03-16 00:00:00 +00:00
12
+ default_executable:
13
+ dependencies: []
14
+
15
+ description: ""
16
+ email: garbagecat10@gmail.com
17
+ executables: []
18
+
19
+ extensions:
20
+ - ext/extconf.rb
21
+ extra_rdoc_files:
22
+ - docs/COPYING
23
+ - docs/README
24
+ - docs/RELEASE_NOTES
31
25
  files:
26
+ - Rakefile
27
+ - docs/COPYING
28
+ - docs/README
29
+ - docs/RELEASE_NOTES
30
+ - eventmachine_httpserver.gemspec
31
+ - eventmachine_httpserver.gemspec.tmpl
32
+ - ext/extconf.rb
32
33
  - ext/http.cpp
33
- - ext/rubyhttp.cpp
34
34
  - ext/http.h
35
- - ext/extconf.rb
36
- - ext/ptch
37
- - lib/evma_httpserver
35
+ - ext/rubyhttp.cpp
38
36
  - lib/evma_httpserver.rb
39
37
  - lib/evma_httpserver/response.rb
40
- - test/app.rb
41
- - test/response.rb
42
- - README
43
- - RELEASE_NOTES
44
- - COPYING
45
- - Rakefile
46
- test_files: []
47
-
38
+ - test/test_app.rb
39
+ - test/test_delegated.rb
40
+ - test/test_response.rb
41
+ has_rdoc: true
42
+ homepage: http://rubyeventmachine.com
43
+ post_install_message:
48
44
  rdoc_options:
49
45
  - --title
50
46
  - EventMachine_HttpServer
51
47
  - --main
52
- - README
48
+ - docs/README
53
49
  - --line-numbers
54
- extra_rdoc_files:
55
- - README
56
- - RELEASE_NOTES
57
- - COPYING
58
- - Rakefile
59
- executables: []
60
-
61
- extensions:
62
- - ext/extconf.rb
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">"
55
+ - !ruby/object:Gem::Version
56
+ version: 0.0.0
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
63
64
  requirements: []
64
65
 
65
- dependencies: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.1
68
+ signing_key:
69
+ specification_version: 1
70
+ summary: EventMachine HTTP Server
71
+ test_files: []
66
72