-
Notifications
You must be signed in to change notification settings - Fork 30
/
test.rb
172 lines (170 loc) · 6.24 KB
/
test.rb
1
2
3
4
5
6
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#
# mod_mruby test sample script
#
# vi /etc/httpd/conf.d/mruby.conf
# LoadModule mruby_module /usr/lib/httpd/modules/mod_mruby.so
# AddHandler mruby-script .rb
#
# access to http://example.com/test.rb
#
module ModMruby
class Test
def initialize
end
def code
end
def start
Apache.echo "# mod_mruby Test Page"
Apache.echo "__mod_mruby test start.__"
end
def finish
Apache.echo "__Test Complete. Wellcome to mod_mruby world!!__"
Apache.return(Apache::OK)
end
def core
Apache.echo "## Apache Class Test"
Apache.echo "- Server: #{server_name}"
Apache.echo "- Apache version: #{Apache::server_version}"
Apache.echo "- Apache build: #{Apache::server_build}"
Apache.echo "- module name: #{Apache::module_name}"
Apache.echo "- module version: #{Apache::module_version}"
Apache.syslogger 4, "mod_mruby warning syslogger test."
Apache.echo "- syslogger function: OK"
Apache.errlogger 4, "mod_mruby warning errlogger test."
Apache.echo "- errlogger function: OK"
Apache.echo "- OK status = #{Apache::OK.to_s}"
Apache.echo "- DECLINED status = #{Apache::DECLINED.to_s}"
Apache.echo "- HTTP_OK status = #{Apache::HTTP_OK.to_s}"
Apache.echo "- HTTP_SERVICE_UNAVAILABLE status = #{Apache::HTTP_SERVICE_UNAVAILABLE.to_s}"
end
def request
Apache.echo "## Request Class Test"
r = Apache::Request.new()
Apache.echo "- filename = #{r.filename}"
Apache.echo "- uri = #{r.uri}"
Apache.echo "- ---- request_rec changed ----"
r.filename = "/var/www/html/index.html"
r.uri = "/index.html"
Apache.echo "- filename = #{r.filename}"
Apache.echo "- uri = #{r.uri}"
p_docroot = r.document_root
Apache.echo "r.document_root: #{r.document_root}"
r.document_root = "/tmp"
Apache.echo "r.document_root: #{r.document_root}"
r.document_root = p_docroot
end
def server
Apache.echo "## Server Class Test"
s = Apache::Server.new()
Apache.echo "- document_root = #{s.document_root}"
Apache.echo "- error_fname = #{s.error_fname}"
Apache.echo "- hostname = #{s.hostname}"
Apache.echo "- timeout = #{s.timeout.to_s}"
end
def connection
Apache.echo "## Connection Class Test"
c = Apache::Connection.new()
Apache.echo "- remote_ip #{c.remote_ip}"
Apache.echo "- local_ip #{c.local_ip}"
Apache.echo "- keepalives = #{c.keepalives.to_s}"
end
def note
Apache.echo "##Notes Class Test"
n = Apache::Request.new.notes
n["memo"] = "hello"
Apache.echo "- memo = #{n['memo']}"
end
def env
Apache.echo "## Env Class Test"
e = Apache::Env.new()
e["AUTHOR"] = "MATSUMOTO Ryosuke"
e["AUTHOR"] = "matsumoto_r"
Apache.echo "- AUTHOR = #{e["AUTHOR"]}"
Apache.echo "- SERVER_SOFTWARE = #{e['SERVER_SOFTWARE'].nil? ? 'nil' : e['SERVER_SOFTWARE']}"
e["SERVER_SOFTWARE"] = "A p a c h e"
eall = e.all
Apache.echo "- env hash size = #{eall.size.to_s}"
eall.each_key do |key|
Apache.echo "- env key = #{key} val = #{eall[key].to_s}"
end
end
def headers_in
Apache.echo "## Headers_in Class Test"
hi = Apache::Request.new.headers_in
Apache.echo "- Accept-Encoding = #{hi['Accept-Encoding'].nil? ? 'nil' : hi['Accept-Encoding']}"
hi["Accept-Encoding"] = "gzip"
Apache.echo "- Accept-Encoding = #{hi["Accept-Encoding"]}"
hiall = hi.all
Apache.echo "- headers_in hash size = #{hiall.size.to_s}"
hiall.each_key do |key|
Apache.echo "- headers_in key = #{key} val = #{hiall[key]}"
end
end
def headers_out
Apache.echo "## Headers_out Class Test"
ho = Apache::Request.new.headers_out
hoall = ho.all
Apache.echo "- headers_out hash size = #{hoall.size.to_s}"
hoall.each_key do |key|
Apache.echo "- headers_in key = #{key} val = #{hoall[key]}"
end
end
def scoreboard
Apache.echo "## Scoreboard Class Test"
wc = Apache::Scoreboard.new()
Apache.echo "- child pid = #{wc.pid.to_s}"
Apache.echo "- thread limit = #{wc.thread_limit.to_s}"
Apache.echo "- server limit = #{wc.server_limit.to_s}"
Apache.echo "__Cannot get below values of scoreboard because of ExtendedStatus Off__" if wc.restart_time == 0
Apache.echo "- cpu load = #{wc.cpu_load.to_s}"
Apache.echo "- load avereage = #{wc.loadavg.to_s}"
Apache.echo "- total kbyte = #{wc.total_kbyte.to_s}"
Apache.echo "- total access = #{wc.total_access.to_s}"
Apache.echo "- restart time = #{wc.restart_time.to_s}"
Apache.echo "- idle worker = #{wc.idle_worker.to_s}"
Apache.echo "- busy worker = #{wc.busy_worker.to_s}"
Apache.echo "- uptime = #{wc.uptime.to_s}"
Apache.echo "- access counter = #{wc.access_counter(wc.pid).to_s}"
Apache.echo "- scoreboard status hash size = #{wc.status.size.to_s}"
wc.status.each_key do |key|
Apache.echo "- scoreboard key = #{key} val = #{wc.status[key]}"
end
Apache.echo "- scoreboard counter hash size = #{wc.counter.size.to_s}"
wc.counter.each_key do |key|
Apache.echo "- scoreboard key = #{key} val = #{wc.counter[key].to_s}"
end
end
def finfo
Apache::echo "## Finfo Class Test"
f = Apache::Request.new.finfo
Apache.echo "- permission = #{f.permission.to_s}"
Apache.echo "- mode = #{"%o" % f.mode}" if f.respond_to?(:mode)
Apache.echo "- filetype regular file = #{f.filetype == Apache::Finfo::APR_REG}"
Apache.echo "- user = #{f.user.to_s}"
Apache.echo "- group = #{f.group.to_s}"
Apache.echo "- device = #{f.device.to_s}"
Apache.echo "- inode = #{f.inode.to_s}"
Apache.echo "- nlink = #{f.nlink.to_s}"
Apache.echo "- size = #{f.size.to_s}"
Apache.echo "- csize = #{f.csize.to_s}"
Apache.echo "- atime = #{f.atime.to_s}"
Apache.echo "- mtime = #{f.mtime.to_s}"
Apache.echo "- ctime = #{f.ctime.to_s}"
end
end
end
t = ModMruby::Test.new
t.start
t.code
t.core
t.request
t.server
t.connection
t.note
t.env
t.headers_in
t.headers_out
t.scoreboard
t.finfo
t.finish
Apache.errlogger 4, "arena count = #{Apache.count_arena.to_s}"