rufus-verbs 0.10 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +64 -0
- data/CREDITS.txt +9 -0
- data/LICENSE.txt +21 -0
- data/README.txt +4 -4
- data/Rakefile +80 -0
- data/doc/rdoc-style.css +320 -0
- data/lib/rufus-verbs.rb +3 -0
- data/lib/rufus/verbs.rb +67 -76
- data/lib/rufus/verbs/conditional.rb +78 -88
- data/lib/rufus/verbs/cookies.rb +214 -224
- data/lib/rufus/verbs/digest.rb +173 -182
- data/lib/rufus/verbs/endpoint.rb +496 -502
- data/lib/rufus/verbs/verbose.rb +52 -61
- data/lib/rufus/verbs/version.rb +6 -16
- data/rufus-verbs.gemspec +87 -0
- data/test/auth0_test.rb +22 -25
- data/test/auth1_test.rb +1 -4
- data/test/base.rb +56 -0
- data/test/block_test.rb +25 -27
- data/test/conditional_test.rb +24 -26
- data/test/cookie0_test.rb +98 -100
- data/test/cookie1_test.rb +28 -30
- data/test/dryrun_test.rb +53 -40
- data/test/escape_test.rb +16 -18
- data/test/fopen_test.rb +31 -33
- data/test/https_test.rb +19 -22
- data/test/iconditional_test.rb +36 -38
- data/test/items.rb +189 -189
- data/test/proxy_test.rb +53 -55
- data/test/redir_test.rb +16 -18
- data/test/simple_test.rb +77 -82
- data/test/test.rb +22 -26
- data/test/timeout_test.rb +15 -19
- data/test/uri_test.rb +12 -14
- metadata +38 -17
- data/test/testbase.rb +0 -47
data/test/escape_test.rb
CHANGED
@@ -7,32 +7,30 @@
|
|
7
7
|
# Tue Feb 12 23:10:54 JST 2008
|
8
8
|
#
|
9
9
|
|
10
|
-
require '
|
11
|
-
|
12
|
-
require 'rufus/verbs'
|
10
|
+
require File.dirname(__FILE__) + '/base.rb'
|
13
11
|
|
14
12
|
|
15
13
|
class EscapeTest < Test::Unit::TestCase
|
16
14
|
|
17
|
-
|
15
|
+
include Rufus::Verbs
|
18
16
|
|
19
17
|
|
20
|
-
|
18
|
+
def test_0
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
req = put(
|
21
|
+
:dry_run => true,
|
22
|
+
:uri => "http://localhost:7777/items/1",
|
23
|
+
:query => { "a" => "hontou ni ?" })
|
26
24
|
|
27
|
-
|
25
|
+
assert_equal "/items/1?a=hontou%20ni%20?", req.path
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
req = put(
|
28
|
+
:dry_run => true,
|
29
|
+
:uri => "http://localhost:7777/items/1",
|
30
|
+
:params => { "a" => "hontou ni ?" },
|
31
|
+
:no_escape => true)
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
assert_equal "/items/1?a=hontou ni ?", req.path
|
34
|
+
# would fail anyway...
|
35
|
+
end
|
38
36
|
end
|
data/test/fopen_test.rb
CHANGED
@@ -7,54 +7,52 @@
|
|
7
7
|
# Mon Feb 18 13:00:36 JST 2008
|
8
8
|
#
|
9
9
|
|
10
|
-
require 'test/unit'
|
11
|
-
require 'testbase'
|
12
10
|
|
13
|
-
require '
|
11
|
+
require File.dirname(__FILE__) + '/base.rb'
|
14
12
|
|
15
13
|
|
16
14
|
class UriTest < Test::Unit::TestCase
|
17
|
-
|
15
|
+
include TestBaseMixin
|
18
16
|
|
19
|
-
|
17
|
+
include Rufus::Verbs
|
20
18
|
|
21
|
-
|
19
|
+
def test_0
|
22
20
|
|
23
|
-
|
21
|
+
uri = "http://localhost:7777/items"
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
res = fopen uri
|
24
|
+
assert_equal 200, res.code.to_i
|
25
|
+
assert_equal "{}", res.body.strip
|
28
26
|
|
29
|
-
|
30
|
-
|
27
|
+
res = fopen "file:CHANGELOG.txt"
|
28
|
+
assert_kind_of String, res.read
|
31
29
|
|
32
|
-
|
33
|
-
|
30
|
+
res = fopen "CHANGELOG.txt"
|
31
|
+
assert_kind_of String, res.read
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
res = fopen "http://localhost:7777/things"
|
34
|
+
assert_equal 200, res.code.to_i
|
35
|
+
assert_equal "{}", res.body.strip
|
36
|
+
#
|
37
|
+
# it follows redirections :)
|
40
38
|
|
41
|
-
|
42
|
-
|
39
|
+
res = fopen "http://localhost:7777/things", :noredir => true
|
40
|
+
assert_equal 303, res.code.to_i
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
fopen "CHANGELOG.txt" do |f|
|
43
|
+
assert_kind_of String, f.read
|
44
|
+
end
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
46
|
+
fopen "http://localhost:7777/things" do |res|
|
47
|
+
assert_equal 200, res.code.to_i
|
48
|
+
assert_equal "{}", res.body.strip
|
52
49
|
end
|
50
|
+
end
|
53
51
|
|
54
|
-
|
52
|
+
def test_1
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
assert_kind_of String, fopen("CHANGELOG.txt").read
|
55
|
+
assert_kind_of String, fopen("file:CHANGELOG.txt").read
|
56
|
+
assert_kind_of String, fopen("http://localhost:7777/items").read
|
57
|
+
end
|
60
58
|
end
|
data/test/https_test.rb
CHANGED
@@ -7,36 +7,33 @@
|
|
7
7
|
# Mon Jan 14 00:07:38 JST 2008
|
8
8
|
#
|
9
9
|
|
10
|
-
require '
|
11
|
-
require 'testbase'
|
12
|
-
|
13
|
-
require 'rufus/verbs'
|
10
|
+
require File.dirname(__FILE__) + '/base.rb'
|
14
11
|
|
15
12
|
|
16
13
|
class HttpsTest < Test::Unit::TestCase
|
17
|
-
|
14
|
+
include TestBaseMixin
|
18
15
|
|
19
|
-
|
16
|
+
include Rufus::Verbs
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
def setup
|
19
|
+
# no need for an items server
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
22
|
+
def teardown
|
23
|
+
end
|
27
24
|
|
28
|
-
|
25
|
+
def test_0
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
res = expect(
|
28
|
+
200,
|
29
|
+
nil,
|
30
|
+
get(:uri => "https://jmettraux.wordpress.com/2006/03/31/cvs-down/"))
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
#res.each_header do |h|
|
33
|
+
# p h
|
34
|
+
#end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
#puts res.body
|
37
|
+
assert res.body.match "^<!DOCTYPE html PUBLIC"
|
38
|
+
end
|
42
39
|
end
|
data/test/iconditional_test.rb
CHANGED
@@ -7,62 +7,60 @@
|
|
7
7
|
# Sun Jan 13 12:33:03 JST 2008
|
8
8
|
#
|
9
9
|
|
10
|
-
require 'test/unit'
|
11
|
-
require 'testbase'
|
12
10
|
|
13
|
-
require '
|
11
|
+
require File.dirname(__FILE__) + '/base.rb'
|
14
12
|
|
15
13
|
|
16
14
|
class ItemConditionalTest < Test::Unit::TestCase
|
17
|
-
|
15
|
+
include TestBaseMixin
|
18
16
|
|
19
|
-
|
17
|
+
include Rufus::Verbs
|
20
18
|
|
21
19
|
|
22
|
-
|
20
|
+
def test_0
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
require 'open-uri'
|
23
|
+
f = open "http://localhost:7777/items"
|
24
|
+
d = f.read
|
25
|
+
f.close
|
28
26
|
|
29
|
-
|
30
|
-
|
27
|
+
assert_equal "{}", d.strip
|
28
|
+
end
|
31
29
|
|
32
|
-
|
30
|
+
def test_1
|
33
31
|
|
34
|
-
|
32
|
+
res = get :uri => "http://localhost:7777/items"
|
35
33
|
|
36
|
-
|
37
|
-
|
34
|
+
assert_equal 200, res.code.to_i
|
35
|
+
assert_equal "{}", res.body.strip
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
p res['Etag']
|
38
|
+
#p res['Last-Modified']
|
39
|
+
assert res['Etag'].length > 0
|
40
|
+
assert res['Last-Modified'].length > 0
|
41
|
+
end
|
44
42
|
|
45
|
-
|
43
|
+
def test_2
|
46
44
|
|
47
|
-
|
48
|
-
|
45
|
+
res = get "http://localhost:7777/items"
|
46
|
+
assert_equal 200, res.code.to_i
|
49
47
|
|
50
|
-
|
51
|
-
|
48
|
+
lm = res['Last-Modified']
|
49
|
+
etag = res['Etag']
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
res = get(
|
52
|
+
"http://localhost:7777/items",
|
53
|
+
:headers => { 'If-Modified-Since' => lm })
|
54
|
+
assert_equal 304, res.code.to_i
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
res = get(
|
57
|
+
"http://localhost:7777/items", :h => { 'If-None-Match' => etag })
|
58
|
+
assert_equal 304, res.code.to_i
|
61
59
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
res = get(
|
61
|
+
"http://localhost:7777/items",
|
62
|
+
:h => { 'If-Modified-Since' => lm, 'If-None-Match' => etag })
|
63
|
+
assert_equal 304, res.code.to_i
|
64
|
+
end
|
67
65
|
end
|
68
66
|
|
data/test/items.rb
CHANGED
@@ -19,36 +19,36 @@ $dcount = 0 # tracking the number of hits when doing digest auth
|
|
19
19
|
#
|
20
20
|
class LastModifiedHash
|
21
21
|
|
22
|
-
|
22
|
+
def initialize
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
@hash = {}
|
25
|
+
touch
|
26
|
+
end
|
27
27
|
|
28
|
-
|
28
|
+
def touch (key=nil)
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
now = Time.now.httpdate
|
31
|
+
@hash[key] = now if key
|
32
|
+
@hash['__self'] = now
|
33
|
+
end
|
34
34
|
|
35
|
-
|
35
|
+
def delete (key)
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
@hash.delete key
|
38
|
+
@hash['__self'] = Time.now.httpdate
|
39
|
+
end
|
40
40
|
|
41
|
-
|
41
|
+
def last_modified (key)
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
key = key || '__self'
|
44
|
+
@hash[key]
|
45
|
+
end
|
46
46
|
|
47
|
-
|
47
|
+
def clear
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
@hash.clear
|
50
|
+
@hash['__self'] = Time.now.httpdate
|
51
|
+
end
|
52
52
|
end
|
53
53
|
|
54
54
|
|
@@ -57,173 +57,173 @@ end
|
|
57
57
|
#
|
58
58
|
class ItemServlet < WEBrick::HTTPServlet::AbstractServlet
|
59
59
|
|
60
|
-
|
61
|
-
|
60
|
+
@@items = {}
|
61
|
+
@@last_item_id = -1
|
62
62
|
|
63
|
-
|
63
|
+
@@lastmod = LastModifiedHash.new
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
@@authenticator = WEBrick::HTTPAuth::DigestAuth.new(
|
66
|
+
:UserDB => WEBrick::HTTPAuth::Htdigest.new('test/test.htdigest'),
|
67
|
+
:Realm => 'test_realm')
|
68
68
|
|
69
|
-
|
69
|
+
def initialize (server, *options)
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
super
|
72
|
+
@auth = server.auth
|
73
|
+
end
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
#
|
76
|
+
# Overriding the service() method to perform a potential auth check
|
77
|
+
#
|
78
|
+
def service (req, res)
|
79
79
|
|
80
|
-
|
80
|
+
if @auth == :basic
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
WEBrick::HTTPAuth.basic_auth(req, res, "items") do |u, p|
|
83
|
+
(u != nil and u == p)
|
84
|
+
end
|
85
85
|
|
86
|
-
|
86
|
+
elsif @auth == :digest
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
super
|
88
|
+
$dcount += 1
|
89
|
+
@@authenticator.authenticate(req, res)
|
93
90
|
end
|
94
91
|
|
95
|
-
|
92
|
+
super
|
93
|
+
end
|
94
|
+
|
95
|
+
def do_GET (req, res)
|
96
96
|
|
97
|
-
|
97
|
+
i = item_id req
|
98
98
|
|
99
|
-
|
100
|
-
|
99
|
+
return reply(res, 404, "no item '#{i}'") \
|
100
|
+
if i and not items[i]
|
101
101
|
|
102
|
-
|
102
|
+
representation, et, lm = fetch_representation i
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
since = req['If-Modified-Since']
|
105
|
+
since = DateTime.parse(since) if since
|
106
|
+
match = req['If-None-Match']
|
107
107
|
|
108
|
-
|
109
|
-
|
110
|
-
|
108
|
+
if ((not since and not match) or
|
109
|
+
(since and (since > DateTime.parse(lm))) or
|
110
|
+
(match and (match != et)))
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
res['Etag'] = et
|
113
|
+
res['Last-Modified'] = lm
|
114
|
+
res.body = representation.inspect + "\n"
|
115
115
|
|
116
|
-
|
116
|
+
else
|
117
117
|
|
118
|
-
|
119
|
-
end
|
118
|
+
reply(res, 304, "Not Modified")
|
120
119
|
end
|
120
|
+
end
|
121
121
|
|
122
|
-
|
122
|
+
def do_POST (req, res)
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
124
|
+
query = WEBrick::HTTPUtils::parse_query(req.query_string)
|
125
|
+
m = query['_method']
|
126
|
+
m = m.downcase if m
|
127
|
+
return do_PUT(req, res) if m == 'put'
|
128
|
+
return do_DELETE(req, res) if m == 'delete'
|
129
129
|
|
130
|
-
|
130
|
+
i = item_id req
|
131
131
|
|
132
|
-
|
132
|
+
i = (@@last_item_id += 1) unless i
|
133
133
|
|
134
|
-
|
135
|
-
|
134
|
+
items[i] = req.body
|
135
|
+
lastmod.touch i
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
137
|
+
res['Location'] = "#{@host}/items/#{i}"
|
138
|
+
reply res, 201, "item created"
|
139
|
+
end
|
140
140
|
|
141
|
-
|
141
|
+
def do_PUT (req, res)
|
142
142
|
|
143
|
-
|
143
|
+
i = item_id req
|
144
144
|
|
145
|
-
|
145
|
+
return reply(res, 404, "no item '#{i}'") unless items[i]
|
146
146
|
|
147
|
-
|
148
|
-
|
147
|
+
items[i] = req.body
|
148
|
+
lastmod.touch i
|
149
149
|
|
150
|
-
|
151
|
-
|
150
|
+
reply res, 200, "item updated"
|
151
|
+
end
|
152
152
|
|
153
|
-
|
153
|
+
def do_DELETE (req, res)
|
154
154
|
|
155
|
-
|
155
|
+
i = item_id req
|
156
156
|
|
157
|
-
|
157
|
+
return reply(res, 404, "no item '#{i}'") unless items[i]
|
158
158
|
|
159
|
-
|
160
|
-
|
159
|
+
items.delete i
|
160
|
+
lastmod.delete i
|
161
161
|
|
162
|
-
|
163
|
-
|
162
|
+
reply res, 200, "item deleted"
|
163
|
+
end
|
164
164
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
165
|
+
#
|
166
|
+
# clears the items
|
167
|
+
#
|
168
|
+
def self.flush
|
169
169
|
|
170
|
-
|
171
|
-
|
172
|
-
|
170
|
+
@@items.clear
|
171
|
+
@@lastmod.clear
|
172
|
+
end
|
173
173
|
|
174
|
-
|
174
|
+
protected
|
175
175
|
|
176
|
-
|
177
|
-
|
178
|
-
|
176
|
+
def items
|
177
|
+
@@items
|
178
|
+
end
|
179
179
|
|
180
|
-
|
181
|
-
|
182
|
-
|
180
|
+
def lastmod
|
181
|
+
@@lastmod
|
182
|
+
end
|
183
183
|
|
184
|
-
|
184
|
+
def is_modified (req, key)
|
185
185
|
|
186
|
-
|
187
|
-
|
186
|
+
since = req['If-Modified-Since']
|
187
|
+
match = req['If-None-Match']
|
188
188
|
|
189
|
-
|
189
|
+
return true unless since or match
|
190
190
|
|
191
|
-
|
192
|
-
|
193
|
-
|
191
|
+
#puts
|
192
|
+
#p [ since, match ]
|
193
|
+
#puts
|
194
194
|
|
195
|
-
|
196
|
-
|
195
|
+
(since or match)
|
196
|
+
end
|
197
197
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
198
|
+
#
|
199
|
+
# Returns representation, etag, last_modified
|
200
|
+
#
|
201
|
+
def fetch_representation (key=nil)
|
202
202
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
203
|
+
representation = if key
|
204
|
+
items[key]
|
205
|
+
else
|
206
|
+
items
|
207
|
+
end
|
208
208
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
209
|
+
[ representation,
|
210
|
+
representation.inspect.hash.to_s,
|
211
|
+
lastmod.last_modified(key) ]
|
212
|
+
end
|
213
213
|
|
214
|
-
|
214
|
+
def reply (res, code, message)
|
215
215
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
216
|
+
res.status = code
|
217
|
+
res.body = message + "\n"
|
218
|
+
res['Content-type'] = "text/plain"
|
219
|
+
end
|
220
220
|
|
221
|
-
|
221
|
+
def item_id (req)
|
222
222
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
223
|
+
p = req.path_info[1..-1]
|
224
|
+
return nil if not p or p == ''
|
225
|
+
p.to_i
|
226
|
+
end
|
227
227
|
end
|
228
228
|
|
229
229
|
#
|
@@ -231,12 +231,12 @@ end
|
|
231
231
|
#
|
232
232
|
class ThingServlet < WEBrick::HTTPServlet::AbstractServlet
|
233
233
|
|
234
|
-
|
234
|
+
def do_GET (req, res)
|
235
235
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
236
|
+
res.set_redirect(
|
237
|
+
WEBrick::HTTPStatus[303],
|
238
|
+
"http://localhost:7777/items")
|
239
|
+
end
|
240
240
|
end
|
241
241
|
|
242
242
|
#
|
@@ -244,35 +244,35 @@ end
|
|
244
244
|
#
|
245
245
|
class CookieServlet < WEBrick::HTTPServlet::AbstractServlet
|
246
246
|
|
247
|
-
|
247
|
+
@@sessions = {}
|
248
248
|
|
249
|
-
|
249
|
+
def do_GET (req, res)
|
250
250
|
|
251
|
-
|
252
|
-
|
251
|
+
res.body = get_session(req, res).inspect
|
252
|
+
end
|
253
253
|
|
254
|
-
|
254
|
+
def do_POST (req, res)
|
255
255
|
|
256
|
-
|
257
|
-
|
258
|
-
|
256
|
+
get_session(req, res) << req.body.strip
|
257
|
+
res.body = "ok."
|
258
|
+
end
|
259
259
|
|
260
|
-
|
260
|
+
protected
|
261
261
|
|
262
|
-
|
262
|
+
def get_session (req, res)
|
263
263
|
|
264
|
-
|
264
|
+
c = req.cookies.find { |c| c.name == 'tcookie' }
|
265
265
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
266
|
+
if c
|
267
|
+
@@sessions[c.value]
|
268
|
+
else
|
269
|
+
s = []
|
270
|
+
key = (Time.now.to_f * 100000).to_i.to_s
|
271
|
+
@@sessions[key] = s
|
272
|
+
res.cookies << WEBrick::Cookie.new('tcookie', key)
|
273
|
+
s
|
274
|
+
end
|
275
|
+
end
|
276
276
|
end
|
277
277
|
|
278
278
|
#
|
@@ -280,10 +280,10 @@ end
|
|
280
280
|
#
|
281
281
|
class LostServlet < WEBrick::HTTPServlet::AbstractServlet
|
282
282
|
|
283
|
-
|
283
|
+
def do_GET (req, res)
|
284
284
|
|
285
|
-
|
286
|
-
|
285
|
+
sleep 200
|
286
|
+
end
|
287
287
|
end
|
288
288
|
|
289
289
|
#
|
@@ -292,42 +292,42 @@ end
|
|
292
292
|
#
|
293
293
|
class ItemServer
|
294
294
|
|
295
|
-
|
295
|
+
def initialize (args={})
|
296
296
|
|
297
|
-
|
297
|
+
port = args[:port] || 7777
|
298
298
|
|
299
|
-
|
300
|
-
|
301
|
-
|
299
|
+
#al = [
|
300
|
+
# [ "", WEBrick::AccessLog::COMMON_LOG_FORMAT ],
|
301
|
+
# [ "", WEBrick::AccessLog::REFERER_LOG_FORMAT ]]
|
302
302
|
|
303
|
-
|
303
|
+
@server = WEBrick::HTTPServer.new :Port => port, :AccessLog => nil
|
304
304
|
|
305
|
-
|
306
|
-
|
307
|
-
|
305
|
+
class << @server
|
306
|
+
attr_accessor :auth
|
307
|
+
end
|
308
308
|
|
309
|
-
|
309
|
+
@server.auth = args[:auth]
|
310
310
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
311
|
+
@server.mount "/items", ItemServlet
|
312
|
+
@server.mount "/things", ThingServlet
|
313
|
+
@server.mount "/cookie", CookieServlet
|
314
|
+
@server.mount "/lost", LostServlet
|
315
315
|
|
316
|
-
|
317
|
-
|
318
|
-
end
|
316
|
+
[ 'INT', 'TERM' ].each do |signal|
|
317
|
+
trap(signal) { shutdown }
|
319
318
|
end
|
319
|
+
end
|
320
320
|
|
321
|
-
|
321
|
+
def start
|
322
322
|
|
323
|
-
|
324
|
-
|
325
|
-
|
323
|
+
Thread.new { @server.start }
|
324
|
+
# else the server and the test lock each other
|
325
|
+
end
|
326
326
|
|
327
|
-
|
327
|
+
def shutdown
|
328
328
|
|
329
|
-
|
330
|
-
|
331
|
-
|
329
|
+
ItemServlet.flush
|
330
|
+
@server.shutdown
|
331
|
+
end
|
332
332
|
end
|
333
333
|
|