eventmachine_httpserver 0.0.1

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.
@@ -0,0 +1,183 @@
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'
9
+ require 'evma_httpserver'
10
+
11
+
12
+ #--------------------------------------
13
+
14
+ module EventMachine
15
+
16
+ # This is a test harness wired into the HttpResponse class so we
17
+ # can test it without requiring any actual network communication.
18
+ #
19
+ class HttpResponse
20
+ attr_reader :output_data
21
+ attr_reader :closed_after_writing
22
+
23
+ def send_data data
24
+ @output_data ||= ""
25
+ @output_data << data
26
+ end
27
+ def close_connection_after_writing
28
+ @closed_after_writing = true
29
+ end
30
+ end
31
+ end
32
+
33
+ #--------------------------------------
34
+
35
+
36
+ class TestHttpResponse < Test::Unit::TestCase
37
+
38
+ def setup
39
+ end
40
+
41
+
42
+ def teardown
43
+ end
44
+
45
+
46
+ def test_properties
47
+ a = EventMachine::HttpResponse.new
48
+ a.status = 200
49
+ a.content = "Some content"
50
+ a.headers["Content-type"] = "text/xml"
51
+ end
52
+
53
+ def test_header_sugarings
54
+ a = EventMachine::HttpResponse.new
55
+ a.content_type "text/xml"
56
+ a.set_cookie "a=b"
57
+ a.headers["X-bayshore"] = "aaaa"
58
+
59
+ assert_equal({
60
+ "Content-type" => "text/xml",
61
+ "Set-cookie" => ["a=b"],
62
+ "X-bayshore" => "aaaa"
63
+ }, a.headers)
64
+ end
65
+
66
+ def test_send_response
67
+ a = EventMachine::HttpResponse.new
68
+ a.status = 200
69
+ a.send_response
70
+ assert_equal([
71
+ "HTTP/1.1 200 ...\r\n",
72
+ "Content-length: 0\r\n",
73
+ "\r\n"
74
+ ].join, a.output_data)
75
+ assert_equal( true, a.closed_after_writing )
76
+ end
77
+
78
+ def test_send_response_1
79
+ a = EventMachine::HttpResponse.new
80
+ a.status = 200
81
+ a.content_type "text/plain"
82
+ a.content = "ABC"
83
+ a.send_response
84
+ assert_equal([
85
+ "HTTP/1.1 200 ...\r\n",
86
+ "Content-length: 3\r\n",
87
+ "Content-type: text/plain\r\n",
88
+ "\r\n",
89
+ "ABC"
90
+ ].join, a.output_data)
91
+ assert( a.closed_after_writing )
92
+ end
93
+
94
+ def test_send_response_no_close
95
+ a = EventMachine::HttpResponse.new
96
+ a.status = 200
97
+ a.content_type "text/plain"
98
+ a.content = "ABC"
99
+ a.keep_connection_open
100
+ a.send_response
101
+ assert_equal([
102
+ "HTTP/1.1 200 ...\r\n",
103
+ "Content-length: 3\r\n",
104
+ "Content-type: text/plain\r\n",
105
+ "\r\n",
106
+ "ABC"
107
+ ].join, a.output_data)
108
+ assert( ! a.closed_after_writing )
109
+ end
110
+
111
+ def test_send_response_multiple_times
112
+ a = EventMachine::HttpResponse.new
113
+ a.status = 200
114
+ a.send_response
115
+ assert_raise( RuntimeError ) {
116
+ a.send_response
117
+ }
118
+ end
119
+
120
+ def test_send_headers
121
+ a = EventMachine::HttpResponse.new
122
+ a.status = 200
123
+ a.send_headers
124
+ assert_equal([
125
+ "HTTP/1.1 200 ...\r\n",
126
+ "Content-length: 0\r\n",
127
+ "\r\n"
128
+ ].join, a.output_data)
129
+ assert( ! a.closed_after_writing )
130
+ assert_raise( RuntimeError ) {
131
+ a.send_headers
132
+ }
133
+ end
134
+
135
+ def test_send_chunks
136
+ a = EventMachine::HttpResponse.new
137
+ a.chunk "ABC"
138
+ a.chunk "DEF"
139
+ a.chunk "GHI"
140
+ a.keep_connection_open
141
+ a.send_response
142
+ assert_equal([
143
+ "HTTP/1.1 200 ...\r\n",
144
+ "Transfer-encoding: chunked\r\n",
145
+ "\r\n",
146
+ "3\r\n",
147
+ "ABC\r\n",
148
+ "3\r\n",
149
+ "DEF\r\n",
150
+ "3\r\n",
151
+ "GHI\r\n",
152
+ "0\r\n",
153
+ "\r\n"
154
+ ].join, a.output_data)
155
+ assert( !a.closed_after_writing )
156
+ end
157
+
158
+ def test_send_chunks_with_close
159
+ a = EventMachine::HttpResponse.new
160
+ a.chunk "ABC"
161
+ a.chunk "DEF"
162
+ a.chunk "GHI"
163
+ a.send_response
164
+ assert_equal([
165
+ "HTTP/1.1 200 ...\r\n",
166
+ "Transfer-encoding: chunked\r\n",
167
+ "\r\n",
168
+ "3\r\n",
169
+ "ABC\r\n",
170
+ "3\r\n",
171
+ "DEF\r\n",
172
+ "3\r\n",
173
+ "GHI\r\n",
174
+ "0\r\n",
175
+ "\r\n"
176
+ ].join, a.output_data)
177
+ assert( a.closed_after_writing )
178
+ end
179
+
180
+ end
181
+
182
+
183
+
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: eventmachine_httpserver
5
+ 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:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Francis Cianfrocca
31
+ files:
32
+ - ext/http.cpp
33
+ - ext/rubyhttp.cpp
34
+ - ext/http.h
35
+ - ext/extconf.rb
36
+ - ext/ptch
37
+ - lib/evma_httpserver
38
+ - lib/evma_httpserver.rb
39
+ - 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
+
48
+ rdoc_options:
49
+ - --title
50
+ - EventMachine_HttpServer
51
+ - --main
52
+ - README
53
+ - --line-numbers
54
+ extra_rdoc_files:
55
+ - README
56
+ - RELEASE_NOTES
57
+ - COPYING
58
+ - Rakefile
59
+ executables: []
60
+
61
+ extensions:
62
+ - ext/extconf.rb
63
+ requirements: []
64
+
65
+ dependencies: []
66
+