switch to a 60 bit hash
[httpd-crcsyncproxy.git] / modules / lua / test / htdocs / test.lua
blobc0b96aba48990a61de0fe6e2f0282132443e6c00
1 -- Licensed to the Apache Software Foundation (ASF) under one or more
2 -- contributor license agreements. See the NOTICE file distributed with
3 -- this work for additional information regarding copyright ownership.
4 -- The ASF licenses this file to You under the Apache License, Version 2.0
5 -- (the "License"); you may not use this file except in compliance with
6 -- the License. You may obtain a copy of the License at
7 --
8 -- http://www.apache.org/licenses/LICENSE-2.0
9 --
10 -- Unless required by applicable law or agreed to in writing, software
11 -- distributed under the License is distributed on an "AS IS" BASIS,
12 -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 -- See the License for the specific language governing permissions and
14 -- limitations under the License.
16 require 'string'
18 function print_args(r, simple, complex)
19 local s = " %s: %s\n"
20 r:puts(" simple:\n")
21 for k, v in pairs(simple) do
22 r:puts(s:format(k, v))
23 end
25 s = " %s: "
26 r:puts(" complex:\n")
27 for k, ary in pairs(complex) do
28 r:puts(s:format(k))
29 for i=1, #ary do
30 r:puts(ary[i])
31 if i < #ary then r:puts(", ") end
32 end
33 r:puts("\n")
34 end
35 end
37 function debug_stuff(r)
38 r:debug("This is a debug log message")
39 -- r:info("This is an info log message")
40 -- r:notice("This is an notice log message")
41 -- r:warn("This is an warn log message")
42 -- r:err("This is an err log message")
43 -- r:alert("This is an alert log message")
44 -- r:crit("This is an crit log message")
45 -- r:emerg("This is an emerg log message")
46 end
48 function handle(r)
49 r:puts("hello Lua world\n")
50 r:puts("Query args:\n")
52 print_args(r, r:parseargs());
54 debug_stuff(r)
56 r:puts("HTTP Method:\n " .. r.method .. "\n")
58 if r.method == 'POST' then
59 print_args(r, r:parsebody())
60 end
62 require("other")
63 r:puts("loaded relative to script:\n ")
64 other.doit(r)
66 r:puts("loaded from LuaPackagePath:\n")
67 require("kangaroo");
68 kangaroo.hop(r);
69 end
71 function handle_foo(r)
72 r:puts("Handler FOO!\n")
73 r.status = 201
74 r:debug("set status to 201")
75 end
78 function handle_attributes(r)
79 local function pf(name)
80 r:puts(("%s: %s\n"):format(name, tostring(r[name])))
81 end
83 pf("status")
84 r.status = 201
85 pf("status")
86 r:puts("\n")
88 pf("content_type")
89 r.content_type = "text/plain?charset=ascii"
90 pf("content_type")
91 r:puts("\n")
93 pf("method")
94 pf("protocol")
95 pf("assbackwards")
96 pf("the_request")
97 pf("range")
98 pf("content_encoding")
99 pf("user")
100 pf("unparsed_uri")
101 pf("ap_auth_type")
102 pf("uri")
103 pf("filename")
104 pf("canonical_filename")
105 pf("path_info")
106 pf("args")
108 r:puts("\n")
111 function test_headers(r)
112 r:puts("test getting and setting headers here\n")
115 function handle_quietly(r)
116 r:puts("hello!")
119 function handle_regex(r)
120 r:puts("matched in handle_regex")
123 function handle_serverversion(r)
124 r:puts(apache2.version)
127 function handle_fixupstest(r)
128 r:puts("status is " .. r.status)