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. 15 16require 'string' 17 18function 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 24 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 35end 36 37function 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") 46end 47 48function handle(r) 49 r:puts("hello Lua world\n") 50 r:puts("Query args:\n") 51 52 print_args(r, r:parseargs()); 53 54 debug_stuff(r) 55 56 r:puts("HTTP Method:\n " .. r.method .. "\n") 57 58 if r.method == 'POST' then 59 print_args(r, r:parsebody()) 60 end 61 62 require("other") 63 r:puts("loaded relative to script:\n ") 64 other.doit(r) 65 66 r:puts("loaded from LuaPackagePath:\n") 67 require("kangaroo"); 68 kangaroo.hop(r); 69end 70 71function handle_foo(r) 72 r:puts("Handler FOO!\n") 73 r.status = 201 74 r:debug("set status to 201") 75end 76 77 78function handle_attributes(r) 79 local function pf(name) 80 r:puts(("%s: %s\n"):format(name, tostring(r[name]))) 81 end 82 83 pf("status") 84 r.status = 201 85 pf("status") 86 r:puts("\n") 87 88 pf("content_type") 89 r.content_type = "text/plain?charset=ascii" 90 pf("content_type") 91 r:puts("\n") 92 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") 107 108 r:puts("\n") 109end 110 111function test_headers(r) 112 r:puts("test getting and setting headers here\n") 113end 114 115function handle_quietly(r) 116 r:puts("hello!") 117end 118 119function handle_regex(r) 120 r:puts("matched in handle_regex") 121end 122 123function handle_serverversion(r) 124 r:puts(apache2.version) 125end 126 127function handle_fixupstest(r) 128 r:puts("status is " .. r.status) 129end