heventmachine_httpserver 0.2.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,184 @@
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
+
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.
22
+ #
23
+ class D
24
+ attr_reader :output_data
25
+ attr_reader :closed_after_writing
26
+
27
+ def send_data data
28
+ @output_data ||= ""
29
+ @output_data << data
30
+ end
31
+ def close_connection_after_writing
32
+ @closed_after_writing = true
33
+ end
34
+ end
35
+
36
+ def setup
37
+ end
38
+
39
+
40
+ def teardown
41
+ end
42
+
43
+
44
+ def test_properties
45
+ a = EM::DelegatedHttpResponse.new( D.new )
46
+ a.status = 200
47
+ a.content = "Some content"
48
+ a.headers["Content-Type"] = "text/xml"
49
+ end
50
+
51
+ def test_header_sugarings
52
+ a = EM::DelegatedHttpResponse.new( D.new )
53
+ a.content_type "text/xml"
54
+ a.set_cookie "a=b"
55
+ a.headers["X-bayshore"] = "aaaa"
56
+
57
+ assert_equal({
58
+ "Content-Type" => "text/xml",
59
+ "Set-Cookie" => ["a=b"],
60
+ "X-bayshore" => "aaaa"
61
+ }, a.headers)
62
+ end
63
+
64
+ def test_send_response
65
+ d = D.new
66
+ a = EM::DelegatedHttpResponse.new( d )
67
+ a.status = 200
68
+ a.send_response
69
+ assert_equal([
70
+ "HTTP/1.1 200 OK\r\n",
71
+ "Content-Length: 0\r\n",
72
+ "\r\n"
73
+ ].join, d.output_data)
74
+ assert_equal( true, d.closed_after_writing )
75
+ end
76
+
77
+ def test_send_response_1
78
+ d = D.new
79
+ a = EM::DelegatedHttpResponse.new( d )
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 OK\r\n",
86
+ "Content-Length: 3\r\n",
87
+ "Content-Type: text/plain\r\n",
88
+ "\r\n",
89
+ "ABC"
90
+ ].join, d.output_data)
91
+ assert( d.closed_after_writing )
92
+ end
93
+
94
+ def test_send_response_no_close
95
+ d = D.new
96
+ a = EM::DelegatedHttpResponse.new( d )
97
+ a.status = 200
98
+ a.content_type "text/plain"
99
+ a.content = "ABC"
100
+ a.keep_connection_open
101
+ a.send_response
102
+ assert_equal([
103
+ "HTTP/1.1 200 OK\r\n",
104
+ "Content-Length: 3\r\n",
105
+ "Content-Type: text/plain\r\n",
106
+ "\r\n",
107
+ "ABC"
108
+ ].join, d.output_data)
109
+ assert( ! d.closed_after_writing )
110
+ end
111
+
112
+ def test_send_response_multiple_times
113
+ a = EM::DelegatedHttpResponse.new( D.new )
114
+ a.status = 200
115
+ a.send_response
116
+ assert_raise( RuntimeError ) {
117
+ a.send_response
118
+ }
119
+ end
120
+
121
+ def test_send_headers
122
+ d = D.new
123
+ a = EM::DelegatedHttpResponse.new( d )
124
+ a.status = 200
125
+ a.send_headers
126
+ assert_equal([
127
+ "HTTP/1.1 200 OK\r\n",
128
+ "Content-Length: 0\r\n",
129
+ "\r\n"
130
+ ].join, d.output_data)
131
+ assert( ! d.closed_after_writing )
132
+ assert_raise( RuntimeError ) {
133
+ a.send_headers
134
+ }
135
+ end
136
+
137
+ def test_send_chunks
138
+ d = D.new
139
+ a = EM::DelegatedHttpResponse.new( d )
140
+ a.chunk "ABC"
141
+ a.chunk "DEF"
142
+ a.chunk "GHI"
143
+ a.keep_connection_open
144
+ a.send_response
145
+ assert_equal([
146
+ "HTTP/1.1 200 OK\r\n",
147
+ "Transfer-Encoding: chunked\r\n",
148
+ "\r\n",
149
+ "3\r\n",
150
+ "ABC\r\n",
151
+ "3\r\n",
152
+ "DEF\r\n",
153
+ "3\r\n",
154
+ "GHI\r\n",
155
+ "0\r\n",
156
+ "\r\n"
157
+ ].join, d.output_data)
158
+ assert( !d.closed_after_writing )
159
+ end
160
+
161
+ def test_send_chunks_with_close
162
+ d = D.new
163
+ a = EM::DelegatedHttpResponse.new( d )
164
+ a.chunk "ABC"
165
+ a.chunk "DEF"
166
+ a.chunk "GHI"
167
+ a.send_response
168
+ assert_equal([
169
+ "HTTP/1.1 200 OK\r\n",
170
+ "Transfer-Encoding: chunked\r\n",
171
+ "\r\n",
172
+ "3\r\n",
173
+ "ABC\r\n",
174
+ "3\r\n",
175
+ "DEF\r\n",
176
+ "3\r\n",
177
+ "GHI\r\n",
178
+ "0\r\n",
179
+ "\r\n"
180
+ ].join, d.output_data)
181
+ assert( d.closed_after_writing )
182
+ end
183
+
184
+ end
@@ -0,0 +1,175 @@
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 OK\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 OK\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 OK\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 OK\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 OK\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 OK\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
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heventmachine_httpserver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Francis Cianfrocca
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email: hunglkt@gmail.com
15
+ executables: []
16
+ extensions:
17
+ - ext/extconf.rb
18
+ extra_rdoc_files:
19
+ - docs/COPYING
20
+ - docs/README
21
+ - docs/RELEASE_NOTES
22
+ files:
23
+ - README.md
24
+ - Rakefile
25
+ - docs/COPYING
26
+ - docs/README
27
+ - docs/RELEASE_NOTES
28
+ - ext/extconf.rb
29
+ - ext/http.cpp
30
+ - ext/http.h
31
+ - ext/rubyhttp.cpp
32
+ - heventmachine_httpserver.gemspec
33
+ - heventmachine_httpserver.gemspec.tmpl
34
+ - lib/evma_httpserver.rb
35
+ - lib/evma_httpserver/response.rb
36
+ - test/test_app.rb
37
+ - test/test_delegated.rb
38
+ - test/test_response.rb
39
+ homepage: https://github.com/hunglkt/eventmachine_httpserver
40
+ licenses: []
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options:
44
+ - "--title"
45
+ - EventMachine_HttpServer
46
+ - "--main"
47
+ - docs/README
48
+ - "--line-numbers"
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.0.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.1.4
63
+ signing_key:
64
+ specification_version: 1
65
+ summary: EventMachine HTTP Server
66
+ test_files: []