fotonauts-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.
- data/.gitignore +7 -0
- data/Rakefile +92 -0
- data/docs/COPYING +281 -0
- data/docs/README +8 -0
- data/docs/RELEASE_NOTES +3 -0
- data/eventmachine_httpserver.gemspec.tmpl +23 -0
- data/ext/extconf.rb +126 -0
- data/ext/http.cpp +566 -0
- data/ext/http.h +115 -0
- data/ext/ptch +148 -0
- data/ext/rubyhttp.cpp +276 -0
- data/lib/evma_httpserver.rb +35 -0
- data/lib/evma_httpserver/response.rb +278 -0
- data/test/test_app.rb +239 -0
- data/test/test_response.rb +178 -0
- metadata +72 -0
@@ -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
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fotonauts-eventmachine_httpserver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francis Cianfrocca
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
date: 2007-03-16 00:00:00 -07: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
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- Rakefile
|
28
|
+
- docs/COPYING
|
29
|
+
- docs/README
|
30
|
+
- docs/RELEASE_NOTES
|
31
|
+
- eventmachine_httpserver.gemspec.tmpl
|
32
|
+
- ext/extconf.rb
|
33
|
+
- ext/http.cpp
|
34
|
+
- ext/http.h
|
35
|
+
- ext/ptch
|
36
|
+
- ext/rubyhttp.cpp
|
37
|
+
- lib/evma_httpserver.rb
|
38
|
+
- lib/evma_httpserver/response.rb
|
39
|
+
- test/test_app.rb
|
40
|
+
- test/test_response.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://rubyeventmachine.com
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --title
|
46
|
+
- EventMachine_HttpServer
|
47
|
+
- --main
|
48
|
+
- docs/README
|
49
|
+
- --line-numbers
|
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:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.2.0
|
68
|
+
signing_key:
|
69
|
+
specification_version: 1
|
70
|
+
summary: EventMachine HTTP Server
|
71
|
+
test_files: []
|
72
|
+
|