7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/rack/hello_world.rb', line 7
def _call(env)
if env['REQUEST_METHOD'] != 'GET'
return [405, {}, ['']]
end
return case env['PATH_INFO']
when '/echo/accept'
[200,
{'Content-Type' => env['HTTP_ACCEPT'], 'Content-Length' => '0'},
[]
]
when '/hello'
[200,
{'Content-Type' => 'text/plain', 'Content-Length' => '12'},
['Hello World!']
]
when '/value'
@@value ||= 0
@@value += 1
[200,
{'Content-Type' => 'text/plain', 'ETag' => rand(0xffff).to_s},
["#{@@value}"]
]
when '/block'
n = 17
[200,
{'Content-Type' => 'text/plain', 'Content-Length' => n.to_s},
['+'*n]
]
when '/code'
[2.05,
{'Content-Type' => 'text/plain'},
[]
]
when '/time'
[200,
{'Content-Type' => 'text/plain'},
[Time.now.to_s]
]
when '/cbor'
require 'json'
body = JSON.parse(env['rack.input'].read).to_s +
env['coap.cbor'].to_s
[200,
{
'Content-Type' => 'text/plain',
'Content-Length' => body.bytesize.to_s
},
[body]
]
when '/json'
require 'json'
body = {'Hello' => 'World!'}.to_json
[200,
{
'Content-Type' => 'application/json; charset=utf8',
'Content-Length' => body.bytesize.to_s
},
[body]
]
else
[404, {}, ['']]
end
end
|